Skip to content

Commit

Permalink
chore(build): Modernise and clean up build
Browse files Browse the repository at this point in the history
- Implement buildSrc to isolate build related code and deps
- Rename gradle plugin project dir to gradle-plugin
- Add gradle dir for version catalogs
- Implement version catalogs to handle versions
- Remove redundant gradle files from subprojects
- Move grailsCentralPublishing.gradle to gradle dir
- Use project.layout to reference files and dirs
- Make build more type-safe with IDE code completion
- Unify quote usage
- Clean up dependencies and tighten their scopes
- Use lazy configuration where possible
- Remove unused ext properties
- Create workarounds for grails-gradle-plugin exposing groovy
- Remove used resources and attribute to asciidoctor task
- Fix classpath issues with groovydoc task
- Change 'docs' task as there is nothing to copy
- Change jar manifest to reflect projects properties
- Remove redundant Application.groovy from views-markup
- Update example projects
- Add missing CompileStatic and make compatible with Groovy 3.0.21-SNAPSHOT
  • Loading branch information
matrei committed Jan 25, 2024
1 parent 9c392e5 commit 858f61b
Show file tree
Hide file tree
Showing 148 changed files with 813 additions and 3,048 deletions.
175 changes: 69 additions & 106 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,124 +1,87 @@
buildscript {
repositories {
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "io.github.gradle-nexus:publish-plugin:1.3.0"
classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
}
}
import io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository

ext {
isReleaseVersion = !project.projectVersion.endsWith('-SNAPSHOT')
grailsVersion = project.grailsVersion
userOrg = "grails"
plugins {
id 'groovy'
id 'io.github.gradle-nexus.publish-plugin'
id 'org.asciidoctor.jvm.convert'
}

apply plugin:'idea'

if (isReleaseVersion) {
apply plugin: 'maven-publish'
apply plugin: "io.github.gradle-nexus.publish-plugin"

nexusPublishing {
repositories {
sonatype {
def ossUser = System.getenv("SONATYPE_USERNAME") ?: project.hasProperty("sonatypeOssUsername") ? project.sonatypeOssUsername : ''
def ossPass = System.getenv("SONATYPE_PASSWORD") ?: project.hasProperty("sonatypeOssPassword") ? project.sonatypeOssPassword : ''
def ossStagingProfileId = System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: project.hasProperty("sonatypeOssStagingProfileId") ? project.sonatypeOssStagingProfileId : ''
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
username = ossUser
password = ossPass
stagingProfileId = ossStagingProfileId
}
version = projectVersion
ext.set('groovyVersion', System.getenv('CI_GROOVY_VERSION') ?: libs.versions.groovy.get())
ext.set('isSnapshot', version.endsWith('-SNAPSHOT'))
ext.set('isReleaseVersion', !isSnapshot)
ext.set('pomInfo', {
delegate.url 'https://views.grails.org/latest/'
delegate.licenses {
delegate.license {
delegate.name 'The Apache Software License, Version 2.0'
delegate.url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}

subprojects { subproject->

version subproject.projectVersion

ext['groovyVersion'] = System.getenv('CI_GROOVY_VERSION') ?: project.groovyVersion

subproject.configurations {
all {
resolutionStrategy {
force 'org.yaml:snakeyaml:1.33'
force 'org.codehaus.groovy:groovy-xml:3.0.13'
force 'org.codehaus.groovy:groovy-sql:3.0.13'

eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.codehaus.groovy' &&
!(details.requested.name in ['groovy-xml', 'groovy-sql'])) {
details.useVersion(groovyVersion)
}
}
}
delegate.scm {
delegate.url 'https://github.com/grails/grails-views/'
delegate.connection 'scm:git:git://github.com/grails/grails-views'
delegate.developerConnection 'scm:git:ssh://github.com:grails/grails-views'
}
delegate.developers {
delegate.developer {
delegate.id 'graemerocher'
delegate.name 'Graeme Rocher'
delegate.email '[email protected]'
}
delegate.developer {
delegate.id 'puneetbehl'
delegate.name 'Puneet Behl'
delegate.email '[email protected]'
}
}
})

allprojects {
version = rootProject.version
repositories {
mavenLocal()
mavenLocal() // Used by Groovy Joint workflow github action after building Groovy
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
maven { url = 'https://repo.grails.org/grails/core' }
if (libs.versions.groovy.get().endsWith('-SNAPSHOT')) {
maven {
name = 'JFrog Groovy snapshot repo'
url = 'https://groovy.jfrog.io/artifactory/libs-snapshot-local'
}
}
}

if (subproject.name.startsWith('examples') || subproject.name.endsWith('docs')) {
return
tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging { events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' }
}

ext.isGrailsPlugin = subproject.name in ['views-markup', 'views-json']

apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java-library'
apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: 'signing'

if (ext.isGrailsPlugin) {
apply plugin: "org.grails.grails-plugin"
tasks.withType(Jar).configureEach {
manifest.attributes(
'Built-By': System.properties['user.name'],
'Created-By': System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",
'Implementation-Title': project.findProperty('projectDesc') ?: 'Grails Views',
'Implementation-Version': project.version,
'Implementation-Vendor': 'grails.org'
)
}
}

sourceCompatibility = 1.11
targetCompatibility = 1.11

apply from: '../publishing/grailsCentralPublishing.gradle'


if (subproject.name in ["views-core", "views-json", "views-markup", "views-json-testing-support"]) {

configurations {
documentation
}

dependencies {
documentation "org.fusesource.jansi:jansi:$jansiVersion"
documentation "org.codehaus.groovy:groovy-dateutil:$groovyVersion"
documentation "info.picocli:picocli:4.7.5"
documentation "com.github.javaparser:javaparser-core:$javaParserCoreVersion"

testImplementation "org.spockframework:spock-core:$spockVersion"
}

tasks.withType(Test) {
useJUnitPlatform()
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
configure {
retry {
maxRetries = 2
maxFailures = 20
failOnPassedAfterRetry = true
}
if (isReleaseVersion) {
nexusPublishing {
String ossUser = System.getenv('SONATYPE_USERNAME') ?: project.findProperty('sonatypeOssUsername') ?: ''
String ossPass = System.getenv('SONATYPE_PASSWORD') ?: project.findProperty('sonatypeOssPassword') ?: ''
String ossStagingProfileId = System.getenv('SONATYPE_STAGING_PROFILE_ID') ?: project.findProperty('sonatypeOssStagingProfileId') ?: ''
repositories {
sonatype {
nexusUrl = uri('https://s01.oss.sonatype.org/service/local/')
username = ossUser
password = ossPass
stagingProfileId = ossStagingProfileId
}
}

groovydoc.classpath = configurations.documentation
}

}

// Do not generate extra load on Nexus with new staging repository if signing fails
tasks.withType(InitializeNexusStagingRepository).configureEach {
shouldRunAfter = tasks.withType(Sign)
}
20 changes: 20 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id 'groovy-gradle-plugin'
}

repositories {
mavenCentral()
maven { url = 'https://repo.grails.org/grails/core' }
}

dependencies {

// Needs to be implementation, as Asciidoctor task is referenced in docs/build.gradle
implementation buildsrcLibs.asciidoctor.gradle.plugin

runtimeOnly buildsrcLibs.assetpipeline.gradle.plugin
runtimeOnly buildsrcLibs.nexus.publish.gradle.plugin
runtimeOnly buildsrcLibs.grails.gradle.plugin
runtimeOnly buildsrcLibs.grails.views.gradle.plugin
runtimeOnly buildsrcLibs.groovydoc.gradle.plugin
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
buildsrcLibs {
from(files('../gradle/buildsrc.libs.versions.toml'))
}
}
}
65 changes: 27 additions & 38 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
buildscript {
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
classpath "io.github.gradle-nexus:publish-plugin:1.3.0"
}
plugins {
id 'groovy'
id 'java-library'
id 'maven-publish'
id 'signing'
}

group "org.grails"
group = 'org.grails'
ext.set('projectDesc', 'Grails Views Core')

ext {
userOrg = 'grails'
repo = 'grails-core'
isGrailsPlugin = false
projectDesc = "Grails Views Core"
}
dependencies {

sourceCompatibility = 1.11
targetCompatibility = 1.11
implementation libs.groovy.core

repositories {
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
implementation libs.grails.core
implementation libs.grails.web.urlmappings
implementation libs.grails.mimetypes
implementation libs.grails.datastore.gorm.support
implementation libs.grails.rest

dependencies {
api "org.grails:grails-encoder:$grailsVersion"
api "org.grails:grails-web-common:$grailsVersion"
api "org.grails:grails-web-url-mappings:$grailsVersion"
api "org.grails:grails-plugin-rest:$grailsVersion"
api "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
api "javax.servlet:javax.servlet-api:$servletApiVersion"
implementation libs.slf4j.api

api libs.caffeine // Used in public api

testImplementation libs.spock.core
}

if (!tasks.findByName("sourcesJar")) {
tasks.register("sourcesJar", Jar) {
classifier = 'sources'
from project.sourceSets.main.allSource
}
java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.baseline.get())
withJavadocJar()
withSourcesJar()
}

if (!tasks.findByName("javadocJar")) {
tasks.register("javadocJar", Jar) {
classifier = 'javadoc'
from groovydoc.outputs
}
tasks.named('javadocJar', Jar) {
from tasks.named('groovydoc')
}

apply from: rootProject.layout.projectDirectory.file('gradle/grailsCentralPublishing.gradle')
Binary file removed core/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions core/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Loading

0 comments on commit 858f61b

Please sign in to comment.