Skip to content

Commit 5f9d7fb

Browse files
authored
build: remove deprecations and prep for Gradle 10 (spiffe#384)
* build: fix Gradle 10 deprecations and modernize configuration Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * A few minor changes Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * Fix warning Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * build: fix Gradle 10 deprecations and modernize configuration Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * A few minor changes Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * Fix warning Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * Fix error Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * Fix error Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> --------- Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
1 parent a363091 commit 5f9d7fb

7 files changed

Lines changed: 155 additions & 128 deletions

File tree

build.gradle

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
plugins {
22
id 'com.google.osdetector' version '1.7.3'
33
id 'jvm-test-suite'
4-
id 'com.vanniktech.maven.publish' version '0.35.0'
4+
id 'com.vanniktech.maven.publish' version '0.35.0' apply false
55
}
66

77
allprojects {
88
repositories {
99
mavenCentral()
1010
}
11-
apply plugin: 'jacoco'
1211
}
1312

1413
subprojects {
@@ -27,14 +26,12 @@ subprojects {
2726
}
2827

2928
apply plugin: 'java-library'
30-
31-
// vanniktech plugin (maven-publish + signing)
29+
apply plugin: 'jacoco'
3230
apply plugin: 'com.vanniktech.maven.publish'
3331

3432
java {
3533
sourceCompatibility = JavaVersion.VERSION_1_8
3634
targetCompatibility = JavaVersion.VERSION_1_8
37-
3835
withSourcesJar()
3936
}
4037

@@ -55,11 +52,8 @@ subprojects {
5552
name.set(project.name)
5653
url.set('https://github.com/spiffe/java-spiffe')
5754

58-
// description is only available after evaluation
59-
afterEvaluate {
60-
if (project.description != null) {
61-
description.set(project.description)
62-
}
55+
if (project.description) {
56+
description.set(project.description)
6357
}
6458

6559
scm {
@@ -90,20 +84,20 @@ subprojects {
9084
}
9185

9286
dependencies {
93-
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.20.0'
94-
implementation group: 'commons-validator', name: 'commons-validator', version: "1.10.1"
87+
implementation "org.apache.commons:commons-lang3:3.20.0"
88+
implementation "commons-validator:commons-validator:1.10.1"
9589

96-
testCompileOnly group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jupiterVersion}"
97-
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jupiterVersion}"
98-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: "${jupiterVersion}"
90+
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
91+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"
92+
testImplementation "org.junit.jupiter:junit-jupiter-params:${jupiterVersion}"
9993

100-
testCompileOnly group: 'org.mockito', name: 'mockito-core', version: "${mockitoVersion}"
101-
testRuntimeOnly group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockitoVersion}"
94+
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
95+
testRuntimeOnly "org.mockito:mockito-junit-jupiter:${mockitoVersion}"
10296

10397
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
104-
testImplementation group: 'uk.org.webcompere', name: 'system-stubs-core', version: '2.0.3' // Last version supporting Java 8
98+
testImplementation "uk.org.webcompere:system-stubs-core:2.0.3"
10599
} else {
106-
testImplementation group: 'uk.org.webcompere', name: 'system-stubs-core', version: '2.1.8'
100+
testImplementation "uk.org.webcompere:system-stubs-core:2.1.8"
107101
}
108102
}
109103

@@ -115,48 +109,56 @@ subprojects {
115109
}
116110
}
117111

118-
afterEvaluate {
119-
// Work around Gradle 8.14.x implicit-dependency validation:
120-
// generateMetadataFileForMavenPublication must run after plainJavadocJar.
121-
tasks.matching { it.name == "generateMetadataFileForMavenPublication" }.configureEach {
122-
dependsOn(tasks.named("plainJavadocJar"))
112+
plugins.withId('com.vanniktech.maven.publish') {
113+
tasks.matching { it.name == 'generateMetadataFileForMavenPublication' }.configureEach {
114+
dependsOn(
115+
tasks.matching { it.name == 'plainJavadocJar' }
116+
)
123117
}
124118
}
125119
}
126120

127-
task jacocoTestReport(type: JacocoReport) {
121+
tasks.register('jacocoTestReport', JacocoReport) {
128122
// Gather execution data from all subprojects
129-
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
123+
executionData.from(
124+
fileTree(rootDir) {
125+
include '**/build/jacoco/*.exec'
126+
}
127+
)
130128

131129
// Add all relevant sourcesets from the subprojects
132-
subprojects.each {
133-
sourceSets it.sourceSets.main
130+
subprojects.each { p ->
131+
sourceSets p.sourceSets.main
134132
}
135133

136134
// Filter out autogenerated or internal code
137-
afterEvaluate {
138-
classDirectories.setFrom(files(classDirectories.files.collect {
139-
fileTree(dir: it, exclude: ['**/grpc/**', '**/exception/**', '**/internal/**'])
140-
}))
141-
}
135+
classDirectories.setFrom(
136+
files(classDirectories.files.collect { dir ->
137+
fileTree(dir: dir, exclude: [
138+
'**/grpc/**',
139+
'**/exception/**',
140+
'**/internal/**'
141+
])
142+
})
143+
)
142144

143145
reports {
144146
xml.required = true
145147
html.required = true
146148
}
147149
}
148150

149-
jacocoTestReport.dependsOn {
150-
subprojects.collectMany { project ->
151-
project.tasks.matching { it.name in ['test'] }
152-
}
151+
tasks.named('jacocoTestReport') {
152+
dependsOn(subprojects.collect { it.tasks.named('test') })
153153
}
154154

155155
// copy submodules jars to a common folder for deploy
156-
task copyJars(type: Copy) {
156+
def copyJars = tasks.register('copyJars', Copy) {
157157
duplicatesStrategy = DuplicatesStrategy.INCLUDE
158-
from subprojects.collect { it.tasks.withType(Jar) }
159-
into "$buildDir/libs"
158+
from(subprojects.collect { it.tasks.withType(Jar) })
159+
into(layout.buildDirectory.dir("libs"))
160160
}
161161

162-
assemble.finalizedBy copyJars
162+
tasks.named('assemble') {
163+
finalizedBy(copyJars)
164+
}

java-spiffe-core/build.gradle

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
}
5-
6-
dependencies {
7-
classpath group: 'com.google.protobuf', name: 'protobuf-gradle-plugin', version: '0.9.5'
8-
}
1+
plugins {
2+
id 'com.google.protobuf' version '0.9.5'
3+
id 'java-library'
4+
id 'java-test-fixtures'
95
}
106

117
description = "Core functionality to fetch, process and validate X.509 and JWT SVIDs and Bundles from the Workload API."
128

13-
apply plugin: 'com.google.protobuf'
14-
apply plugin: 'java-test-fixtures'
15-
169
sourceSets {
1710
main {
1811
java {
@@ -22,80 +15,107 @@ sourceSets {
2215
}
2316

2417
integrationTest {
25-
java {
26-
compileClasspath += main.output + test.output
27-
runtimeClasspath += main.output + test.output
28-
srcDir file('src/integrationTest/java')
29-
}
18+
java.srcDir file('src/integrationTest/java')
3019
resources.srcDir file('src/integrationTest/resources')
20+
21+
compileClasspath += sourceSets.main.output + sourceSets.test.output
22+
runtimeClasspath += sourceSets.main.output + sourceSets.test.output
3123
}
3224
}
3325

34-
sourcesJar.duplicatesStrategy = DuplicatesStrategy.INCLUDE
26+
tasks.named('sourcesJar') {
27+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
28+
}
3529

3630
configurations {
37-
integrationTestImplementation.extendsFrom testImplementation
38-
integrationTestCompile.extendsFrom testCompile
39-
integrationTestCompileOnly.extendsFrom testCompileOnly
40-
integrationTestRuntime.extendsFrom testRuntime
41-
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
31+
integrationTestImplementation.extendsFrom(testImplementation)
32+
integrationTestRuntimeOnly.extendsFrom(testRuntimeOnly)
33+
integrationTestCompileOnly.extendsFrom(testCompileOnly)
34+
35+
protocTool
36+
grpcTool
4237
}
4338

44-
task integrationTest(type: Test) {
39+
tasks.register('integrationTest', Test) {
40+
description = 'Runs integration tests.'
41+
group = 'verification'
42+
4543
useJUnitPlatform()
4644
testClassesDirs = sourceSets.integrationTest.output.classesDirs
4745
classpath = sourceSets.integrationTest.runtimeClasspath
48-
outputs.upToDateWhen { false }
49-
}
5046

51-
protobuf {
52-
protoc {
53-
artifact = 'com.google.protobuf:protoc:3.25.5'
54-
}
55-
plugins {
56-
grpc {
57-
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
58-
}
59-
}
60-
generateProtoTasks {
61-
all()*.plugins {
62-
grpc {}
63-
}
64-
}
47+
shouldRunAfter(tasks.named('test'))
6548
}
6649

50+
def protocExe = "com.google.protobuf:protoc:3.25.5:${osdetector.classifier}@exe"
51+
def grpcExe = "io.grpc:protoc-gen-grpc-java:${grpcVersion}:${osdetector.classifier}@exe"
52+
6753
dependencies {
68-
if (osdetector.os.is('osx') ) {
69-
project.ext.osArch = System.getProperty("os.arch")
70-
if ("x86_64" == project.ext.osArch) {
54+
protocTool protocExe
55+
grpcTool grpcExe
56+
57+
def osArch = System.getProperty("os.arch")
58+
59+
if (osdetector.os.is('osx')) {
60+
if (osArch == "x86_64") {
7161
compileOnly(project('grpc-netty-macos'))
7262
testImplementation(project('grpc-netty-macos'))
73-
} else if ("aarch64" == project.ext.osArch) {
63+
} else if (osArch == "aarch64") {
7464
compileOnly(project('grpc-netty-macos-aarch64'))
7565
testImplementation(project('grpc-netty-macos-aarch64'))
7666
} else {
77-
throw new GradleException("Architecture not supported: " + project.ext.osArch)
67+
throw new GradleException("Architecture not supported: ${osArch}")
7868
}
7969
} else {
8070
compileOnly(project('grpc-netty-linux'))
8171
testImplementation(project('grpc-netty-linux'))
8272
}
8373

84-
project.ext.osArch = System.getProperty("os.arch")
74+
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
75+
implementation "io.grpc:grpc-stub:${grpcVersion}"
76+
testImplementation "io.grpc:grpc-inprocess:${grpcVersion}"
77+
testImplementation "io.grpc:grpc-testing:${grpcVersion}"
78+
79+
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
80+
81+
implementation "com.nimbusds:nimbus-jose-jwt:${nimbusVersion}"
82+
testFixturesImplementation "com.nimbusds:nimbus-jose-jwt:${nimbusVersion}"
8583

84+
testFixturesImplementation "org.bouncycastle:bcpkix-jdk15on:1.70"
85+
testFixturesImplementation "org.apache.commons:commons-lang3:3.20.0"
86+
}
87+
88+
protobuf {
89+
protoc {
90+
path = configurations.protocTool.singleFile.absolutePath
91+
}
92+
plugins {
93+
grpc {
94+
path = configurations.grpcTool.singleFile.absolutePath
95+
}
96+
}
97+
generateProtoTasks {
98+
all().configureEach {
99+
plugins {
100+
grpc {}
101+
}
102+
}
103+
}
104+
}
86105

87-
implementation group: 'io.grpc', name: 'grpc-protobuf', version: "${grpcVersion}"
88-
implementation group: 'io.grpc', name: 'grpc-stub', version: "${grpcVersion}"
89-
testImplementation group: 'io.grpc', name: 'grpc-inprocess', version: "${grpcVersion}"
90-
testImplementation group: 'io.grpc', name: 'grpc-testing', version: "${grpcVersion}"
91-
compileOnly group: 'org.apache.tomcat', name: 'annotations-api', version: '6.0.53' // necessary for Java 9+
106+
import com.google.protobuf.gradle.GenerateProtoTask
92107

93-
// library for processing JWT tokens and JOSE JWK bundles
94-
implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: "${nimbusVersion}"
95-
testFixturesImplementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: "${nimbusVersion}"
108+
def protocBin = configurations.protocTool.singleFile
109+
def grpcBin = configurations.grpcTool.singleFile
96110

97-
// using bouncy castle for generating X.509 certs for testing purposes
98-
testFixturesImplementation group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.70'
99-
testFixturesImplementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.20.0'
111+
tasks.register("makeProtoToolsExecutable") {
112+
inputs.files(protocBin, grpcBin)
113+
doLast {
114+
protocBin.setExecutable(true, false)
115+
grpcBin.setExecutable(true, false)
116+
}
100117
}
101118

119+
tasks.withType(GenerateProtoTask).configureEach {
120+
dependsOn(tasks.named("makeProtoToolsExecutable"))
121+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
description = "Java SPIFFE Library GRPC-Netty Linux support module"
22

33
dependencies {
4-
implementation group: 'io.grpc', name: 'grpc-netty-shaded', version: "${grpcVersion}"
4+
implementation "io.grpc:grpc-netty-shaded:${grpcVersion}"
55
}
66

77
jar {
8-
archiveClassifier = ""
8+
archiveClassifier = ''
99
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
description = "Java SPIFFE Library GRPC-Netty MacOS module"
22

33
dependencies {
4-
implementation group: 'io.grpc', name: 'grpc-netty', version: "${grpcVersion}"
4+
implementation "io.grpc:grpc-netty:${grpcVersion}"
55

66
// version must match the one in grpc-netty
7-
implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: "${nettyVersion}", classifier: 'osx-aarch_64'
7+
implementation "io.netty:netty-transport-native-kqueue:${nettyVersion}:osx-aarch_64"
88
}
99

10-
jar {
11-
archiveClassifier = ""
10+
tasks.named('jar') {
11+
archiveClassifier = ''
1212
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
description = "Java SPIFFE Library GRPC-Netty MacOS module"
22

33
dependencies {
4-
implementation group: 'io.grpc', name: 'grpc-netty', version: "${grpcVersion}"
5-
implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: "${nettyVersion}", classifier: 'osx-x86_64'
4+
implementation "io.grpc:grpc-netty:${grpcVersion}"
5+
implementation "io.netty:netty-transport-native-kqueue:${nettyVersion}:osx-x86_64"
66
}
77

8-
jar {
9-
archiveClassifier = ""
8+
tasks.named('jar') {
9+
archiveClassifier = ''
1010
}

0 commit comments

Comments
 (0)