Skip to content

Commit e52e135

Browse files
andrrossreta
andauthored
Upgrade to Gradle 9.4 (opensearch-project#20833)
* Upgrade to Gradle 9.4 Also replace the eager cross-project task reference to :libs:agent-sm:agent with Gradle-idiomatic patterns: - Add a consumable agentDist configuration in the agent project that publishes the prepareAgent output directory as an artifact with a Category attribute. - Add a matching resolvable agent configuration in the distribution subprojects to consume it via normal dependency resolution. - Replace direct task references (project.prepareAgent, project.jar) with lazy alternatives: tasks.named() for task providers, lazy GStrings for deferred path resolution, and closure-based dependsOn. This removes the need for an evaluationDependsOn call which forced the agent project to be configured before the distribution project, violating Gradle best practices around project isolation and configuration-time coupling. Signed-off-by: Andrew Ross <andrross@amazon.com> * Refactor the agent wiring to use configurations Signed-off-by: Andriy Redko <drreta@gmail.com> * Use .singleFile and lazy evaluation for agentJar Signed-off-by: Andrew Ross <andrross@amazon.com> --------- Signed-off-by: Andrew Ross <andrross@amazon.com> Signed-off-by: Andriy Redko <drreta@gmail.com> Co-authored-by: Andriy Redko <drreta@gmail.com>
1 parent 341dc34 commit e52e135

File tree

9 files changed

+69
-11
lines changed

9 files changed

+69
-11
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ gradle.projectsEvaluated {
426426

427427
// Add Java Agent for security sandboxing
428428
if (!(project.path in [':build-tools', ":libs:agent-sm:bootstrap", ":libs:agent-sm:agent"])) {
429-
dependsOn(project(':libs:agent-sm:agent').prepareAgent)
430-
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get()]
429+
dependsOn(project(':libs:agent-sm:agent').tasks.named('prepareAgent'))
430+
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').tasks.named('jar').get().archiveFile.get()]
431431
}
432432
if (BuildParams.isInFipsJvm()) {
433433
def fipsSecurityFile = project.rootProject.file('distribution/src/config/fips_java.security')

buildSrc/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ if (project != rootProject) {
291291
suppressPomMetadataWarningsFor("testFixturesApiElements")
292292
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
293293
}
294+
295+
// Gradle 9.4 changed the default to enforce stricter validation. Disabling
296+
// the validation for now and will follow up with a fix.
297+
tasks.validatePlugins {
298+
enableStricterValidation = false
299+
}
294300
}
295301

296302
// Define this here because we need it early. It uses VersionCatalogsExtension to extract all versions

distribution/archives/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,6 @@ tasks.configureEach { t ->
256256

257257
tasks.each {
258258
if (it.name.startsWith("build")) {
259-
it.dependsOn project(':libs:agent-sm:agent').assemble
259+
it.dependsOn project(':libs:agent-sm:agent').tasks.named('assemble')
260260
}
261261
}

distribution/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import java.nio.file.Path
4444
plugins {
4545
id 'base'
4646
}
47+
48+
4749
/*****************************************************************************
4850
* Third party dependencies report *
4951
*****************************************************************************/
@@ -320,6 +322,13 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
320322
}
321323
}
322324
}
325+
create('agent') {
326+
canBeConsumed = false
327+
canBeResolved = true
328+
attributes {
329+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'agent-dist'))
330+
}
331+
}
323332
}
324333

325334
dependencies {
@@ -333,6 +342,8 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
333342
libsFipsInstallerCli project(path: ':distribution:tools:fips-demo-installer-cli')
334343

335344
bcFips libs.bundles.bouncycastle
345+
346+
agent project(path: ':libs:agent-sm:agent', configuration: 'agentDist')
336347
}
337348

338349
project.ext {
@@ -362,7 +373,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
362373

363374
agentFiles = {
364375
copySpec {
365-
from(project(':libs:agent-sm:agent').prepareAgent) {
376+
from(configurations.agent) {
366377
include '**/*.jar'
367378
exclude '**/*-javadoc.jar'
368379
exclude '**/*-sources.jar'

gradle/wrapper/gradle-wrapper.jar

1.83 KB
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists
8-
distributionSha256Sum=f86344275d1b194688dd330abf9f6f2344cd02872ffee035f2d1ea2fd60cf7f3
8+
distributionSha256Sum=b21468753cb43c167738ee04f10c706c46459cf8f8ae6ea132dc9ce589a261f2

libs/agent-sm/agent/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ base {
77

88
configurations {
99
bootstrap.extendsFrom(implementation)
10+
agentDist {
11+
canBeConsumed = true
12+
canBeResolved = false
13+
attributes {
14+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'agent-dist'))
15+
}
16+
}
17+
agentJar {
18+
canBeConsumed = true
19+
canBeResolved = false
20+
attributes {
21+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'agent-jar'))
22+
}
23+
}
1024
}
1125

1226
dependencies {
@@ -53,6 +67,13 @@ task prepareAgent(type: Copy) {
5367
dependsOn jar
5468
}
5569

70+
artifacts {
71+
agentJar(jar)
72+
agentDist(file("$buildDir/distributions")) {
73+
builtBy prepareAgent
74+
}
75+
}
76+
5677
thirdPartyAudit {
5778
ignoreMissingClasses(
5879
'com.sun.jna.FunctionMapper',

plugins/repository-hdfs/build.gradle

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ testFixtures.useFixture ":test:fixtures:krb5kdc-fixture", "hdfs"
5151

5252
configurations {
5353
hdfsFixture
54+
agent {
55+
canBeConsumed = false
56+
canBeResolved = true
57+
attributes {
58+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'agent-jar'))
59+
}
60+
}
5461
}
5562

5663
dependencies {
@@ -88,6 +95,8 @@ dependencies {
8895
if (isEclipse == false) {
8996
testRuntimeOnly files(project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs", "hdfs_hdfs.build.opensearch.org.keytab").parent)
9097
}
98+
99+
agent project(path: ':libs:agent-sm:agent', configuration: 'agentJar')
91100
}
92101

93102
restResources {
@@ -130,7 +139,7 @@ project(':test:fixtures:krb5kdc-fixture').tasks.preProcessFixture {
130139
// Create HDFS File System Testing Fixtures for HA/Secure combinations
131140
for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', 'secureHaHdfsFixture']) {
132141
def tsk = tasks.register(fixtureName, org.opensearch.gradle.test.AntFixture) {
133-
dependsOn configurations.hdfsFixture, project(':test:fixtures:krb5kdc-fixture').tasks.postProcessFixture, project(':libs:agent-sm:agent').prepareAgent
142+
dependsOn configurations.hdfsFixture, project(':test:fixtures:krb5kdc-fixture').tasks.postProcessFixture, configurations.agent
134143
executable = "${BuildParams.runtimeJavaHome}/bin/java"
135144
env 'CLASSPATH', "${-> configurations.hdfsFixture.asPath}"
136145
maxWaitInSeconds = 60
@@ -140,10 +149,10 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture',
140149
// it's ready, so we can just wait for the file to exist
141150
return fixture.portsFile.exists()
142151
}
143-
final List<String> miniHDFSArgs = []
152+
final List miniHDFSArgs = []
144153

145154
// See please https://issues.apache.org/jira/browse/HADOOP-19486
146-
miniHDFSArgs.add("-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get())
155+
miniHDFSArgs.add("-javaagent:${-> configurations.agent.incoming.artifactView({}).files.singleFile}")
147156

148157
// If it's a secure fixture, then depend on Kerberos Fixture and principals + add the krb5conf to the JVM options
149158
if (fixtureName.equals('secureHdfsFixture') || fixtureName.equals('secureHaHdfsFixture')) {

test/framework/build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ apply plugin: 'opensearch.build'
3333
apply plugin: 'opensearch.publish'
3434
apply from: "$rootDir/gradle/fips.gradle"
3535

36+
configurations {
37+
agent {
38+
canBeConsumed = false
39+
canBeResolved = true
40+
attributes {
41+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'agent-jar'))
42+
}
43+
}
44+
}
45+
3646
dependencies {
3747
api project(":client:rest")
3848
api project(":client:sniffer")
@@ -60,6 +70,8 @@ dependencies {
6070
compileOnly "com.github.spotbugs:spotbugs-annotations:4.9.8"
6171

6272
annotationProcessor "org.apache.logging.log4j:log4j-core:${versions.log4j}"
73+
74+
agent project(path: ':libs:agent-sm:agent', configuration: 'agentJar')
6375
}
6476

6577
compileJava.options.compilerArgs -= '-Xlint:cast'
@@ -105,8 +117,7 @@ test {
105117
systemProperty 'tests.gradle_wire_compat_versions', BuildParams.bwcVersions.wireCompatible.join(',')
106118
systemProperty 'tests.gradle_unreleased_versions', BuildParams.bwcVersions.unreleased.join(',')
107119

108-
dependsOn(project(':libs:agent-sm:agent').prepareAgent)
109-
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get()]
120+
jvmArgs += ["-javaagent:${-> configurations.agent.incoming.artifactView({}).files.singleFile}"]
110121
}
111122

112123
tasks.register("integTest", Test) {

0 commit comments

Comments
 (0)