Skip to content

Commit f34d9cc

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-42
1 parent 34bb321 commit f34d9cc

File tree

14 files changed

+898
-206
lines changed

14 files changed

+898
-206
lines changed

build.gradle

Lines changed: 38 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -16,188 +16,50 @@ buildscript {
1616
}
1717
}
1818
dependencies {
19-
classpath "org.graceframework:grace-gradle-plugin:$graceVersion"
20-
classpath "io.github.gradle-nexus:publish-plugin:2.0.0"
19+
classpath "org.graceframework:grace-gradle-plugin:${libs.versions.grace.framework.get()}"
2120
}
2221
}
2322

24-
logger.lifecycle "GORM VERSION = ${project.datastoreVersion}"
23+
plugins {
24+
id 'java-library'
25+
id 'groovy'
26+
id 'maven-publish'
27+
id 'signing'
28+
id 'eclipse'
29+
id 'idea'
30+
// alias libs.plugins.grace.doc
31+
alias libs.plugins.gradle.nexus.publish
32+
}
2533

26-
group = "org.graceframework"
27-
version = project.projectVersion
34+
apply plugin: 'org.graceframework.grace-doc'
2835

2936
ext {
3037
isCiBuild = project.hasProperty("isCiBuild") || System.getenv().get("CI") as Boolean
3138
isBuildSnapshot = project.version.endsWith("-SNAPSHOT")
3239
isReleaseVersion = !isBuildSnapshot
3340
}
3441

35-
ext."signing.keyId" = System.getenv("SIGNING_KEY") ?: project.hasProperty("signing.keyId") ? project.getProperty('signing.keyId') : null
36-
ext."signing.password" = System.getenv("SIGNING_PASSPHRASE") ?: project.hasProperty("signing.password") ? project.getProperty('signing.password') : null
37-
ext."signing.secretKeyRingFile" = project.hasProperty("signing.secretKeyRingFile") ? project.getProperty('signing.secretKeyRingFile') : null
42+
ext."signing.keyId" = project.hasProperty("signing.keyId") ? project.getProperty('signing.keyId') : System.getenv('SIGNING_KEY')
43+
ext."signing.password" = project.hasProperty("signing.password") ? project.getProperty('signing.password') : System.getenv('SIGNING_PASSPHRASE')
44+
ext."signing.secretKeyRingFile" = project.hasProperty("signing.secretKeyRingFile") ? project.getProperty('signing.secretKeyRingFile') : ("${System.properties['user.home']}${File.separator}.gnupg${File.separator}secring.gpg")
45+
ext.isReleaseVersion = !projectVersion.endsWith("SNAPSHOT")
3846

39-
apply plugin: 'groovy'
40-
apply plugin: 'maven-publish'
41-
apply plugin: "io.github.gradle-nexus.publish-plugin"
42-
apply plugin: 'org.graceframework.grace-doc'
47+
version = project.projectVersion
48+
group = "org.graceframework"
4349

44-
nexusPublishing {
45-
repositories {
46-
sonatype {
47-
def mavenUser = System.getenv("MAVEN_CENTRAL_USER") ?: project.hasProperty("mavenCentralUsername") ? project.mavenCentralUsername : ''
48-
def mavenPass = System.getenv("MAVEN_CENTRAL_PASSWORD") ?: project.hasProperty("mavenCentralPassword") ? project.mavenCentralPassword : ''
49-
nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/")
50-
snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/")
51-
username = mavenUser
52-
password = mavenPass
53-
}
54-
}
50+
repositories {
51+
mavenCentral()
5552
}
5653

57-
allprojects {
58-
ext {
59-
groovyVersion = System.getenv('CI_GROOVY_VERSION') ?: project.groovyVersion
60-
}
61-
62-
repositories {
63-
mavenCentral()
64-
maven {
65-
name = 'Maven Central Portal Snapshots'
66-
url = 'https://central.sonatype.com/repository/maven-snapshots/'
67-
68-
content {
69-
includeGroupAndSubgroups 'org.graceframework'
70-
}
71-
mavenContent {
72-
snapshotsOnly()
73-
}
74-
}
75-
}
76-
77-
configurations {
78-
documentation
79-
}
80-
81-
dependencies {
82-
documentation "com.github.javaparser:javaparser-core:$javaParserCoreVersion"
83-
documentation "org.apache.groovy:groovy:$groovyVersion"
84-
documentation "org.apache.groovy:groovy-ant:$groovyVersion"
85-
}
54+
configurations {
55+
documentation
8656
}
8757

88-
subprojects { project ->
89-
if (project.name == 'docs') {
90-
return
91-
}
92-
93-
apply plugin: 'groovy'
94-
apply plugin: "java-library"
95-
apply plugin: 'maven-publish'
96-
apply plugin: 'signing'
97-
apply plugin: "io.spring.dependency-management"
98-
99-
sourceCompatibility = "17"
100-
targetCompatibility = "17"
101-
102-
java {
103-
withJavadocJar()
104-
withSourcesJar()
105-
}
106-
107-
dependencyManagement {
108-
imports {
109-
mavenBom "org.graceframework:grace-bom:$graceVersion"
110-
}
111-
applyMavenExclusions false
112-
generatedPomCustomization {
113-
enabled = false
114-
}
115-
}
116-
117-
dependencies {
118-
api "org.apache.groovy:groovy"
119-
120-
testImplementation "org.apache.groovy:groovy-json"
121-
testImplementation "org.apache.groovy:groovy-templates"
122-
testImplementation "org.apache.groovy:groovy-test-junit5", {
123-
exclude group: "org.junit.platform", module: "junit-platform-launcher"
124-
exclude group: "org.junit.jupiter", module: "junit-jupiter-engine"
125-
}
126-
testImplementation "org.spockframework:spock-core", {
127-
exclude group: "org.junit.platform", module: "junit-platform-engine"
128-
}
129-
testImplementation "org.junit.jupiter:junit-jupiter-api"
130-
testImplementation "org.junit.platform:junit-platform-runner"
131-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
132-
}
133-
134-
publishing {
135-
publications {
136-
maven(MavenPublication) {
137-
def projectArtifactId = project.name
138-
def projectName = project.name.split('-')*.capitalize().join(' ')
139-
140-
artifactId projectArtifactId
141-
from components.java
142-
143-
versionMapping {
144-
usage('java-api') {
145-
fromResolutionOf('runtimeClasspath')
146-
}
147-
usage('java-runtime') {
148-
fromResolutionResult()
149-
}
150-
}
151-
152-
pom {
153-
name = projectName
154-
description = "Grace Data : $projectName"
155-
url = 'https://github.com/graceframework/grace-data-mongodb'
156-
157-
licenses {
158-
license {
159-
name = 'The Apache Software License, Version 2.0'
160-
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
161-
distribution = 'repo'
162-
}
163-
}
164-
165-
scm {
166-
url = 'https://github.com/graceframework/grace-data-mongodb'
167-
connection = 'scm:[email protected]:graceframework/grace-data-mongodb.git'
168-
developerConnection = 'scm:[email protected]:graceframework/grace-data-mongodb.git'
169-
}
170-
171-
developers {
172-
developer {
173-
id = 'rainboyan'
174-
name = 'Michael Yan'
175-
176-
}
177-
}
178-
}
179-
}
180-
}
181-
}
182-
183-
afterEvaluate {
184-
signing {
185-
required { isReleaseVersion }
186-
sign publishing.publications.maven
187-
}
188-
}
189-
190-
tasks.withType(Sign) {
191-
onlyIf { isReleaseVersion }
192-
}
193-
194-
//do not generate extra load on Nexus with new staging repository if signing fails
195-
tasks.withType(io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository).configureEach {
196-
shouldRunAfter(tasks.withType(Sign))
197-
}
58+
dependencies {
59+
documentation libs.javaparser
60+
documentation libs.groovy.core
19861
}
19962

200-
20163
def cleanTask = project.tasks.findByName('clean')
20264
if (cleanTask == null) {
20365
task clean(type: Delete) {
@@ -240,3 +102,16 @@ publishGuide {
240102
task docs {
241103
dependsOn groovydoc, publishGuide
242104
}
105+
106+
nexusPublishing {
107+
repositories {
108+
sonatype {
109+
def mavenUser = System.getenv("MAVEN_CENTRAL_USER") ?: project.hasProperty("mavenCentralUsername") ? project.mavenCentralUsername : ''
110+
def mavenPass = System.getenv("MAVEN_CENTRAL_PASSWORD") ?: project.hasProperty("mavenCentralPassword") ? project.mavenCentralPassword : ''
111+
nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/")
112+
snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/")
113+
username = mavenUser
114+
password = mavenPass
115+
}
116+
}
117+
}

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+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
plugins {
2+
id 'java-library'
3+
id 'groovy'
4+
id 'maven-publish'
5+
id 'signing'
6+
id 'checkstyle'
7+
id 'codenarc'
8+
}
9+
10+
version = project.projectVersion
11+
group = "org.graceframework"
12+
13+
repositories {
14+
mavenCentral()
15+
gradlePluginPortal()
16+
if (project.projectVersion.endsWith('-SNAPSHOT')) {
17+
maven {
18+
name = 'Maven Central Portal Snapshots'
19+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
20+
21+
content {
22+
includeGroupAndSubgroups 'org.graceframework'
23+
}
24+
mavenContent {
25+
snapshotsOnly()
26+
}
27+
}
28+
}
29+
}
30+
31+
configurations {
32+
documentation
33+
}
34+
35+
36+
dependencies {
37+
api libs.groovy.core
38+
39+
testImplementation libs.groovy.test.junit5
40+
testImplementation libs.junit.jupiter.api
41+
testImplementation libs.junit.jupiter.engine
42+
testImplementation libs.junit.platform.runner
43+
testImplementation libs.spock.core
44+
45+
documentation libs.javaparser
46+
documentation libs.groovy.ant
47+
documentation libs.groovy.core
48+
}
49+
50+
compileTestGroovy {
51+
configure(groovyOptions.forkOptions) {
52+
jvmArgs = [ '-Xmx768m']
53+
}
54+
}
55+
56+
java {
57+
toolchain {
58+
languageVersion = JavaLanguageVersion.of(17)
59+
}
60+
withJavadocJar()
61+
withSourcesJar()
62+
}
63+
64+
javadoc {
65+
failOnError = false
66+
}
67+
68+
test {
69+
useJUnitPlatform()
70+
}
71+
72+
configure([javadoc]) {
73+
options.encoding "UTF-8"
74+
options.docEncoding "UTF-8"
75+
options.charSet "UTF-8"
76+
options.jFlags "-Xms64M", "-Xmx512M"
77+
}
78+
79+
checkstyle {
80+
toolVersion = "10.26.1"
81+
configDirectory.set(rootProject.file("config/checkstyle"))
82+
}
83+
84+
codenarc {
85+
toolVersion = '3.6.0'
86+
config = resources.text.fromFile(rootProject.file("config/codenarc/codenarc.groovy"))
87+
}
88+
89+
publishing {
90+
publications {
91+
maven(MavenPublication) {
92+
def projectName = project.name.split('-')*.capitalize().join(' ')
93+
groupId = project.group
94+
version = project.version
95+
96+
versionMapping {
97+
usage('java-api') {
98+
fromResolutionOf('runtimeClasspath')
99+
}
100+
usage('java-runtime') {
101+
fromResolutionResult()
102+
}
103+
}
104+
105+
from components.java
106+
107+
pom {
108+
name = projectName
109+
description = "Grace Data : $projectName"
110+
url = 'https://github.com/graceframework/grace-data-mongodb'
111+
licenses {
112+
license {
113+
name = 'The Apache License, Version 2.0'
114+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
115+
}
116+
}
117+
developers {
118+
developer {
119+
id = 'rainboyan'
120+
name = 'Michael Yan'
121+
122+
}
123+
}
124+
scm {
125+
connection = 'scm:git:git://github.com/graceframework/grace-data-mongodb.git'
126+
developerConnection = 'scm:git:ssh://github.com:graceframework/grace-data-mongodb.git'
127+
url = 'https://github.com/graceframework/grace-data-mongodb/'
128+
}
129+
}
130+
}
131+
}
132+
}
133+
134+
afterEvaluate {
135+
signing {
136+
required = isReleaseVersion && gradle.taskGraph.hasTask("publish")
137+
sign publishing.publications.maven
138+
}
139+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
^\Q/*\E$
2+
^\Q * Copyright \E20\d\d(-20\d\d)?(, \d\d\d\d)*\ the original author or authors.$
3+
^\Q *\E$
4+
^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$
5+
^\Q * you may not use this file except in compliance with the License.\E$
6+
^\Q * You may obtain a copy of the License at\E$
7+
^\Q *\E$
8+
^\Q * https://www.apache.org/licenses/LICENSE-2.0\E$
9+
^\Q *\E$
10+
^\Q * Unless required by applicable law or agreed to in writing, software\E$
11+
^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$
12+
^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$
13+
^\Q * See the License for the specific language governing permissions and\E$
14+
^\Q * limitations under the License.\E$
15+
^\Q */\E$

0 commit comments

Comments
 (0)