Skip to content

Commit c1b63bc

Browse files
committed
Restructure Gradle builds
- Use Gradle version catalog to simplify dependency management - Sharing Build Logic using buildSrc - Update Checkstyle and CodeNarc plugin - Update CI to skip checkstyle and codenarc - Remove publishing directory Closes gh-8
1 parent 8eda16e commit c1b63bc

File tree

25 files changed

+923
-272
lines changed

25 files changed

+923
-272
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: gradle/actions/setup-gradle@017a9effdb900e5b5b2fddfb590a105619dca3c3 # v4.4.2
3434
- name: Run Build
3535
id: build
36-
run: ./gradlew build
36+
run: ./gradlew build -x codenarcMain -x codenarcTest -x checkstyleMain -x checkstyleTest
3737
publish:
3838
if: github.event_name == 'push'
3939
needs: ["build"]

build.gradle

Lines changed: 41 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,42 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
gradlePluginPortal()
5-
}
6-
dependencies {
7-
classpath "io.github.gradle-nexus:publish-plugin:2.0.0"
8-
classpath "org.graceframework:grace-gradle-plugin:$graceVersion"
9-
classpath "org.gradle:test-retry-gradle-plugin:1.6.0"
10-
}
11-
}
12-
13-
ext {
14-
isReleaseVersion = !project.projectVersion.endsWith('-SNAPSHOT')
15-
graceVersion = project.graceVersion
16-
userOrg = "graceframework"
1+
plugins {
2+
id 'java-library'
3+
id 'groovy'
4+
id 'maven-publish'
5+
id 'signing'
6+
id 'eclipse'
7+
id 'idea'
8+
alias libs.plugins.grace.doc
9+
alias libs.plugins.gradle.nexus.publish
10+
alias libs.plugins.gradle.test.retry
1711
}
1812

13+
ext.'signing.keyId' = rootProject.hasProperty('signing.keyId') ? rootProject.getProperty('signing.keyId') : System.getenv('SIGNING_KEY')
14+
ext.'signing.password' = rootProject.hasProperty('signing.password') ? rootProject.getProperty('signing.password') : System.getenv('SIGNING_PASSPHRASE')
15+
ext.'signing.secretKeyRingFile' = rootProject.hasProperty('signing.secretKeyRingFile') ? rootProject.getProperty('signing.secretKeyRingFile') : "${System.properties['user.home']}${File.separator}.gnupg${File.separator}secring.gpg"
16+
ext.isReleaseVersion = !projectVersion.endsWith('SNAPSHOT')
1917

2018
version = project.projectVersion
19+
group = 'org.graceframework.events'
2120

22-
apply plugin:'idea'
23-
24-
apply plugin: 'groovy'
25-
apply plugin: 'maven-publish'
26-
apply plugin: "io.github.gradle-nexus.publish-plugin"
27-
apply plugin: 'org.graceframework.grace-doc'
28-
29-
nexusPublishing {
30-
repositories {
31-
sonatype {
32-
def mavenUser = System.getenv("MAVEN_CENTRAL_USER") ?: project.hasProperty("mavenCentralUsername") ? project.mavenCentralUsername : ''
33-
def mavenPass = System.getenv("MAVEN_CENTRAL_PASSWORD") ?: project.hasProperty("mavenCentralPassword") ? project.mavenCentralPassword : ''
34-
nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/")
35-
snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/")
36-
username = mavenUser
37-
password = mavenPass
38-
}
39-
}
21+
configurations {
22+
documentation
4023
}
4124

42-
allprojects {
43-
repositories {
44-
mavenCentral()
45-
if (project.projectVersion.endsWith('-SNAPSHOT')) {
46-
maven {
47-
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
48-
}
25+
tasks.withType(Test) {
26+
useJUnitPlatform()
27+
testLogging {
28+
showStandardStreams = true
29+
exceptionFormat = 'full'
30+
}
31+
configure {
32+
retry {
33+
maxRetries = 2
34+
maxFailures = 20
35+
failOnPassedAfterRetry = true
4936
}
5037
}
51-
52-
configurations {
53-
documentation
54-
}
55-
56-
dependencies {
57-
documentation "com.github.javaparser:javaparser-core:$javaParserCoreVersion"
58-
documentation "org.apache.groovy:groovy:$groovyVersion"
59-
documentation "org.apache.groovy:groovy-ant:$groovyVersion"
60-
documentation "org.apache.groovy:groovy-dateutil:$groovyVersion"
61-
}
6238
}
6339

64-
subprojects { project->
65-
if (project.name.startsWith('grace-plugin')) {
66-
group = "org.graceframework.plugins"
67-
}
68-
else {
69-
group = "org.graceframework.events"
70-
}
71-
version = project.projectVersion
72-
73-
nexusPublishing {
74-
if (project.name.startsWith('grace-plugin')) {
75-
packageGroup = 'org.graceframework.plugins'
76-
}
77-
else {
78-
packageGroup = "org.graceframework.events"
79-
}
80-
}
81-
82-
if (project.name.startsWith('examples') || project.name.endsWith('docs')) {
83-
return
84-
}
85-
86-
apply plugin: 'eclipse'
87-
apply plugin: 'idea'
88-
apply plugin: 'java-library'
89-
apply plugin: 'groovy'
90-
apply plugin: 'maven-publish'
91-
apply plugin: 'signing'
92-
apply plugin: "org.gradle.test-retry"
93-
94-
if (project.name.startsWith('grace-plugin')) {
95-
apply plugin: 'org.graceframework.grace-plugin'
96-
}
97-
else {
98-
apply plugin: "io.spring.dependency-management"
99-
100-
dependencyManagement {
101-
imports {
102-
mavenBom "org.graceframework:grace-bom:$graceVersion"
103-
}
104-
applyMavenExclusions false
105-
generatedPomCustomization {
106-
enabled = false
107-
}
108-
}
109-
}
110-
111-
if (project.name.startsWith('grace-')) {
112-
dependencies {
113-
api "org.apache.groovy:groovy"
114-
api "org.slf4j:slf4j-api"
115-
116-
testImplementation "org.slf4j:slf4j-simple"
117-
testImplementation "org.spockframework:spock-core", {
118-
exclude group: "org.junit.platform", module: "junit-platform-engine"
119-
}
120-
testImplementation "net.bytebuddy:byte-buddy"
121-
testImplementation "org.objenesis:objenesis:$objenesisVersion"
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.junit.jupiter:junit-jupiter-api"
127-
testImplementation "org.junit.platform:junit-platform-runner"
128-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
129-
}
130-
131-
java {
132-
toolchain {
133-
languageVersion = JavaLanguageVersion.of(17)
134-
}
135-
withJavadocJar()
136-
withSourcesJar()
137-
}
138-
139-
tasks.withType(Test) {
140-
useJUnitPlatform()
141-
testLogging {
142-
showStandardStreams = true
143-
exceptionFormat = 'full'
144-
}
145-
configure {
146-
retry {
147-
maxRetries = 2
148-
maxFailures = 20
149-
failOnPassedAfterRetry = true
150-
}
151-
}
152-
}
153-
154-
tasks.named('compileJava') {
155-
inputs.files(tasks.named('processResources'))
156-
}
157-
}
158-
159-
apply from: '../publishing/mavenCentral.gradle'
160-
}
161-
162-
16340
def cleanTask = project.tasks.findByName('clean')
16441
if (cleanTask == null) {
16542
task clean(type: Delete) {
@@ -198,3 +75,16 @@ docs {
19875
dependsOn groovydoc
19976
sourceDir = project.file('src/main/docs')
20077
}
78+
79+
nexusPublishing {
80+
repositories {
81+
sonatype {
82+
def mavenUser = System.getenv('MAVEN_CENTRAL_USER') ?: project.hasProperty('mavenCentralUsername') ? project.mavenCentralUsername : ''
83+
def mavenPass = System.getenv('MAVEN_CENTRAL_PASSWORD') ?: project.hasProperty('mavenCentralPassword') ? project.mavenCentralPassword : ''
84+
nexusUrl = uri('https://ossrh-staging-api.central.sonatype.com/service/local/')
85+
snapshotRepositoryUrl = uri('https://central.sonatype.com/repository/maven-snapshots/')
86+
username = mavenUser
87+
password = mavenPass
88+
}
89+
}
90+
}

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: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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.events'
12+
13+
repositories {
14+
mavenLocal()
15+
mavenCentral()
16+
gradlePluginPortal()
17+
if (project.projectVersion.endsWith('-SNAPSHOT')) {
18+
maven {
19+
name = 'Maven Central Portal Snapshots'
20+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
21+
22+
content {
23+
includeGroupAndSubgroups 'org.graceframework'
24+
}
25+
mavenContent {
26+
snapshotsOnly()
27+
}
28+
}
29+
}
30+
}
31+
32+
configurations {
33+
documentation
34+
}
35+
36+
dependencies {
37+
api libs.groovy.core
38+
api libs.slf4j.api
39+
40+
testImplementation libs.bytebuddy
41+
testImplementation libs.objenesis
42+
testImplementation libs.groovy.test.junit5, {
43+
exclude group: 'org.junit.platform', module: 'junit-platform-launcher'
44+
exclude group: 'org.junit.jupiter', module: 'junit-jupiter-engine'
45+
}
46+
testImplementation libs.junit.jupiter.api
47+
testImplementation libs.junit.jupiter.engine
48+
testImplementation libs.junit.platform.runner
49+
testImplementation libs.slf4j.simple
50+
testImplementation libs.spock.core, {
51+
transitive = false
52+
}
53+
54+
documentation libs.javaparser
55+
documentation libs.groovy.ant
56+
documentation libs.groovy.core
57+
}
58+
59+
compileTestGroovy {
60+
configure(groovyOptions.forkOptions) {
61+
jvmArgs = [ '-Xmx768m']
62+
}
63+
}
64+
65+
java {
66+
toolchain {
67+
languageVersion = JavaLanguageVersion.of(17)
68+
}
69+
withJavadocJar()
70+
withSourcesJar()
71+
}
72+
73+
jar {
74+
manifest.mainAttributes(
75+
"Built-By": System.properties['user.name'],
76+
"Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",
77+
"Implementation-Title": "Grace Events",
78+
"Implementation-Version": version,
79+
"Implementation-Vendor": 'graceframework.org')
80+
}
81+
82+
javadoc {
83+
failOnError = false
84+
}
85+
86+
test {
87+
useJUnitPlatform()
88+
}
89+
90+
tasks.named('compileJava') {
91+
inputs.files(tasks.named('processResources'))
92+
}
93+
94+
configure([javadoc]) {
95+
options.encoding "UTF-8"
96+
options.docEncoding "UTF-8"
97+
options.charSet "UTF-8"
98+
options.jFlags "-Xms64M", "-Xmx512M"
99+
}
100+
101+
checkstyle {
102+
toolVersion = '10.26.1'
103+
configDirectory.set(rootProject.file('config/checkstyle'))
104+
}
105+
106+
codenarc {
107+
toolVersion = '3.6.0'
108+
config = resources.text.fromFile(rootProject.file('config/codenarc/codenarc.groovy'))
109+
}
110+
111+
publishing {
112+
publications {
113+
maven(MavenPublication) {
114+
groupId = project.group
115+
version = project.version
116+
117+
versionMapping {
118+
usage('java-api') {
119+
fromResolutionOf('runtimeClasspath')
120+
}
121+
usage('java-runtime') {
122+
fromResolutionResult()
123+
}
124+
}
125+
126+
from components.java
127+
128+
pom {
129+
def projectName = project.name.split('-')*.capitalize().join(' ')
130+
name = projectName
131+
description = "Grace Events Framework : $projectName"
132+
url = 'https://github.com/graceframework/grace-async'
133+
licenses {
134+
license {
135+
name = 'The Apache License, Version 2.0'
136+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
137+
}
138+
}
139+
scm {
140+
connection = 'scm:git:git://github.com/graceframework/grace-events.git'
141+
developerConnection = 'scm:git:ssh://github.com:graceframework/grace-events.git'
142+
url = 'https://github.com/graceframework/grace-events'
143+
}
144+
developers {
145+
developer {
146+
id = 'rainboyan'
147+
name = 'Michael Yan'
148+
email = 'rain@rainboyan.com'
149+
}
150+
}
151+
}
152+
}
153+
}
154+
}
155+
156+
afterEvaluate {
157+
signing {
158+
required = isReleaseVersion && gradle.taskGraph.hasTask('publish')
159+
sign publishing.publications.maven
160+
}
161+
}

0 commit comments

Comments
 (0)