Skip to content

Commit 34737f1

Browse files
committed
Restructure Gradle builds
- Use Gradle version catalog to simplify dependency management - Sharing Build Logic using buildSrc - Update Checkstyle and CodeNarc plugin Closes gh-127
1 parent 38f4ad0 commit 34737f1

File tree

11 files changed

+882
-336
lines changed

11 files changed

+882
-336
lines changed

build.gradle

Lines changed: 36 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -15,258 +15,44 @@ buildscript {
1515
}
1616
}
1717
dependencies {
18-
classpath "io.github.gradle-nexus:publish-plugin:2.0.0"
19-
classpath "org.graceframework:grace-gradle-plugin:$graceVersion"
20-
classpath "org.gradle:test-retry-gradle-plugin:1.6.0"
18+
classpath "org.graceframework:grace-gradle-plugin:${libs.versions.grace.framework.get()}"
2119
}
2220
}
2321

24-
group = "org.graceframework"
25-
version = project.projectVersion
26-
27-
ext {
28-
isTravisBuild = System.getenv().get("TRAVIS") == 'true'
29-
isCiBuild = project.hasProperty("isCiBuild") || System.getenv().get("CI") as Boolean
30-
isBuildSnapshot = version.endsWith('-SNAPSHOT')
31-
isReleaseVersion = !isBuildSnapshot
22+
plugins {
23+
id 'java-library'
24+
id 'groovy'
25+
id 'maven-publish'
26+
id 'signing'
27+
id 'eclipse'
28+
id 'idea'
29+
// alias libs.plugins.grace.doc
30+
alias libs.plugins.gradle.nexus.publish
3231
}
3332

34-
ext."signing.keyId" = System.getenv("SIGNING_KEY") ?: project.hasProperty("signing.keyId") ? project.getProperty('signing.keyId') : null
35-
ext."signing.password" = System.getenv("SIGNING_PASSPHRASE") ?: project.hasProperty("signing.password") ? project.getProperty('signing.password') : null
36-
ext."signing.secretKeyRingFile" = project.hasProperty("signing.secretKeyRingFile") ? project.getProperty('signing.secretKeyRingFile') : null
37-
38-
// Build with the current version of GORM
39-
ext['grace-data.version'] = project.gormVersion
40-
41-
logger.lifecycle "GORM VERSION = ${project.gormVersion}"
42-
43-
apply plugin: 'groovy'
44-
apply plugin: 'maven-publish'
45-
apply plugin: "io.github.gradle-nexus.publish-plugin"
4633
apply plugin: 'org.graceframework.grace-doc'
4734

48-
allprojects {
49-
repositories {
50-
mavenCentral()
51-
maven {
52-
name = 'Maven Central Portal Snapshots'
53-
url = 'https://central.sonatype.com/repository/maven-snapshots/'
54-
55-
content {
56-
includeGroupAndSubgroups 'org.graceframework'
57-
}
58-
mavenContent {
59-
snapshotsOnly()
60-
}
61-
}
62-
}
35+
ext."signing.keyId" = project.hasProperty("signing.keyId") ? project.getProperty('signing.keyId') : System.getenv('SIGNING_KEY')
36+
ext."signing.password" = project.hasProperty("signing.password") ? project.getProperty('signing.password') : System.getenv('SIGNING_PASSPHRASE')
37+
ext."signing.secretKeyRingFile" = project.hasProperty("signing.secretKeyRingFile") ? project.getProperty('signing.secretKeyRingFile') : ("${System.properties['user.home']}${File.separator}.gnupg${File.separator}secring.gpg")
38+
ext.isReleaseVersion = !projectVersion.endsWith("SNAPSHOT")
6339

64-
configurations {
65-
documentation
66-
}
40+
version = project.projectVersion
41+
group = "org.graceframework"
6742

68-
dependencies {
69-
documentation "com.github.javaparser:javaparser-core:$javaParserCoreVersion"
70-
documentation "org.apache.groovy:groovy:$groovyVersion"
71-
documentation "org.apache.groovy:groovy-ant:$groovyVersion"
72-
}
43+
repositories {
44+
mavenCentral()
7345
}
7446

75-
nexusPublishing {
76-
repositories {
77-
sonatype {
78-
def mavenUser = System.getenv("MAVEN_CENTRAL_USER") ?: project.hasProperty("mavenCentralUsername") ? project.mavenCentralUsername : ''
79-
def mavenPass = System.getenv("MAVEN_CENTRAL_PASSWORD") ?: project.hasProperty("mavenCentralPassword") ? project.mavenCentralPassword : ''
80-
nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/")
81-
snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/")
82-
username = mavenUser
83-
password = mavenPass
84-
}
85-
}
47+
configurations {
48+
documentation
8649
}
8750

88-
subprojects { Project subproject ->
89-
ext {
90-
projectArtifactId = subproject.name
91-
isPluginProject = subproject.name == 'hibernate'
92-
}
93-
94-
if (isPluginProject) {
95-
group = "org.graceframework.plugins"
96-
}
97-
else {
98-
group = "org.graceframework"
99-
}
100-
version = project.rootProject.version
101-
102-
repositories {
103-
mavenCentral()
104-
maven {
105-
name = 'Maven Central Portal Snapshots'
106-
url = 'https://central.sonatype.com/repository/maven-snapshots/'
107-
108-
content {
109-
includeGroupAndSubgroups 'org.graceframework'
110-
}
111-
mavenContent {
112-
snapshotsOnly()
113-
}
114-
}
115-
}
116-
117-
apply plugin: 'groovy'
118-
119-
configurations {
120-
documentation.extendsFrom(compileClasspath)
121-
}
122-
123-
if (subproject.name == 'docs') {
124-
return
125-
}
126-
127-
apply plugin: 'java-library'
128-
apply plugin: 'maven-publish'
129-
apply plugin: 'checkstyle'
130-
apply plugin: 'codenarc'
131-
apply plugin: 'signing'
132-
apply plugin: "org.gradle.test-retry"
133-
134-
if (isPluginProject) {
135-
apply plugin: 'org.graceframework.grace-plugin'
136-
}
137-
else {
138-
apply plugin: "io.spring.dependency-management"
139-
140-
dependencyManagement {
141-
imports {
142-
mavenBom "org.graceframework:grace-bom:$graceVersion"
143-
}
144-
applyMavenExclusions false
145-
generatedPomCustomization {
146-
enabled = false
147-
}
148-
}
149-
}
150-
151-
dependencies {
152-
testImplementation "org.spockframework:spock-core", {
153-
exclude group: "org.junit.platform", module: "junit-platform-engine"
154-
}
155-
testImplementation "org.apache.groovy:groovy-test-junit5", {
156-
exclude group: "org.junit.platform", module: "junit-platform-launcher"
157-
exclude group: "org.junit.jupiter", module: "junit-jupiter-engine"
158-
}
159-
testImplementation "org.junit.jupiter:junit-jupiter-api"
160-
testImplementation "org.junit.platform:junit-platform-runner"
161-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
162-
}
163-
164-
java {
165-
toolchain {
166-
languageVersion = JavaLanguageVersion.of(17)
167-
}
168-
withJavadocJar()
169-
withSourcesJar()
170-
}
171-
172-
tasks.withType(Test) {
173-
useJUnitPlatform()
174-
testLogging {
175-
showStandardStreams = true
176-
exceptionFormat = 'full'
177-
}
178-
configure {
179-
retry {
180-
maxRetries = 2
181-
maxFailures = 20
182-
failOnPassedAfterRetry = true
183-
}
184-
}
185-
}
186-
187-
publishing {
188-
publications {
189-
maven(MavenPublication) {
190-
def projectName = subproject.name.split('-')*.capitalize().join(' ')
191-
artifactId = projectArtifactId
192-
193-
from components.java
194-
195-
versionMapping {
196-
usage('java-api') {
197-
fromResolutionOf('runtimeClasspath')
198-
}
199-
usage('java-runtime') {
200-
fromResolutionResult()
201-
}
202-
}
203-
204-
afterEvaluate {
205-
if(isPluginProject) {
206-
artifact source:"${sourceSets.main.groovy.classesDirectory.get()}/META-INF/grails-plugin.xml",
207-
classifier:"plugin",
208-
extension:'xml'
209-
}
210-
}
211-
pom {
212-
name = projectName
213-
description = "Grace Data : $projectName"
214-
url = 'https://github.com/graceframework/grace-data-hibernate'
215-
216-
licenses {
217-
license {
218-
name = 'The Apache Software License, Version 2.0'
219-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
220-
distribution = 'repo'
221-
}
222-
}
223-
224-
scm {
225-
url = 'https://github.com/graceframework/grace-data-hibernate'
226-
connection = 'https://github.com/graceframework/grace-data-hibernate'
227-
developerConnection = 'https://github.com/graceframework/grace-data-hibernate'
228-
}
229-
230-
developers {
231-
developer {
232-
id = 'rainboyan'
233-
name = 'Michael Yan'
234-
235-
}
236-
}
237-
}
238-
}
239-
}
240-
}
241-
242-
afterEvaluate {
243-
signing {
244-
required = isReleaseVersion && gradle.taskGraph.hasTask("publish")
245-
sign publishing.publications.maven
246-
}
247-
}
248-
249-
tasks.withType(Sign) {
250-
onlyIf { isReleaseVersion }
251-
}
252-
253-
tasks.named('compileGroovy') {
254-
inputs.files(tasks.named('processResources'))
255-
}
256-
257-
checkstyle {
258-
toolVersion = "10.26.1"
259-
configDirectory.set(rootProject.file("$rootDir/gradle/checkstyle"))
260-
}
261-
262-
codenarc {
263-
toolVersion = '3.6.0'
264-
setConfigFile(new File("$rootDir/gradle/codenarc/codenarc.groovy"))
265-
}
266-
51+
dependencies {
52+
documentation libs.javaparser
53+
documentation libs.groovy.core
26754
}
26855

269-
27056
def cleanTask = project.tasks.findByName('clean')
27157
if (cleanTask == null) {
27258
task clean(type: Delete) {
@@ -305,3 +91,16 @@ publishGuide {
30591
dependsOn groovydoc
30692
sourceDir = project.file('src/docs')
30793
}
94+
95+
nexusPublishing {
96+
repositories {
97+
sonatype {
98+
def mavenUser = System.getenv("MAVEN_CENTRAL_USER") ?: project.hasProperty("mavenCentralUsername") ? project.mavenCentralUsername : ''
99+
def mavenPass = System.getenv("MAVEN_CENTRAL_PASSWORD") ?: project.hasProperty("mavenCentralPassword") ? project.mavenCentralPassword : ''
100+
nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/")
101+
snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/")
102+
username = mavenUser
103+
password = mavenPass
104+
}
105+
}
106+
}

buildSrc/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id 'groovy-gradle-plugin'
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}

0 commit comments

Comments
 (0)