Skip to content

Commit 929105f

Browse files
committed
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>
1 parent aab0a3d commit 929105f

File tree

8 files changed

+39
-11
lines changed

8 files changed

+39
-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')

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ base {
77

88
configurations {
99
bootstrap.extendsFrom(implementation)
10+
create('agentDist') {
11+
canBeConsumed = true
12+
canBeResolved = false
13+
attributes {
14+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, 'agent-dist'))
15+
}
16+
}
1017
}
1118

1219
dependencies {
@@ -53,6 +60,12 @@ task prepareAgent(type: Copy) {
5360
dependsOn jar
5461
}
5562

63+
artifacts {
64+
agentDist(file("$buildDir/distributions")) {
65+
builtBy prepareAgent
66+
}
67+
}
68+
5669
thirdPartyAudit {
5770
ignoreMissingClasses(
5871
'com.sun.jna.FunctionMapper',

plugins/repository-hdfs/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ project(':test:fixtures:krb5kdc-fixture').tasks.preProcessFixture {
130130
// Create HDFS File System Testing Fixtures for HA/Secure combinations
131131
for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', 'secureHaHdfsFixture']) {
132132
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
133+
dependsOn configurations.hdfsFixture, project(':test:fixtures:krb5kdc-fixture').tasks.postProcessFixture
134+
dependsOn { project(':libs:agent-sm:agent').tasks.named('prepareAgent') }
134135
executable = "${BuildParams.runtimeJavaHome}/bin/java"
135136
env 'CLASSPATH', "${-> configurations.hdfsFixture.asPath}"
136137
maxWaitInSeconds = 60
@@ -140,10 +141,10 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture',
140141
// it's ready, so we can just wait for the file to exist
141142
return fixture.portsFile.exists()
142143
}
143-
final List<String> miniHDFSArgs = []
144+
final List miniHDFSArgs = []
144145

145146
// See please https://issues.apache.org/jira/browse/HADOOP-19486
146-
miniHDFSArgs.add("-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get())
147+
miniHDFSArgs.add("-javaagent:${-> project(':libs:agent-sm:agent').tasks.named('jar').get().archiveFile.get()}")
147148

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

test/framework/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ test {
105105
systemProperty 'tests.gradle_wire_compat_versions', BuildParams.bwcVersions.wireCompatible.join(',')
106106
systemProperty 'tests.gradle_unreleased_versions', BuildParams.bwcVersions.unreleased.join(',')
107107

108-
dependsOn(project(':libs:agent-sm:agent').prepareAgent)
109-
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get()]
108+
def agentJarFile = project(':libs:agent-sm:agent').tasks.named('jar').map { it.archiveFile.get() }
109+
dependsOn { project(':libs:agent-sm:agent').tasks.named('prepareAgent') }
110+
doFirst {
111+
jvmArgs "-javaagent:" + agentJarFile.get()
112+
}
110113
}
111114

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

0 commit comments

Comments
 (0)