Skip to content

Commit a4c291f

Browse files
nodeceCopilot
andauthored
[fix][broker] Avoid Project access in broker test setup (apache#25529)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 744d2b8 commit a4c291f

2 files changed

Lines changed: 34 additions & 17 deletions

File tree

pulsar-broker/build.gradle.kts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,43 @@ evaluationDependsOn(":pulsar-io")
141141
evaluationDependsOn(":pulsar-functions")
142142

143143
// NAR/JAR files needed by broker tests (mirrors Maven's maven-dependency-plugin config).
144+
// Resolve through dependency configurations instead of cross-project task references.
145+
val testNars by configurations.creating {
146+
isCanBeResolved = true
147+
isCanBeConsumed = false
148+
attributes {
149+
attribute(org.gradle.api.artifacts.type.ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "nar")
150+
}
151+
}
152+
val testExamplesJar by configurations.creating {
153+
isCanBeResolved = true
154+
isCanBeConsumed = false
155+
}
156+
157+
dependencies {
158+
testNars(project(":pulsar-functions:pulsar-functions-api-examples-builtin"))
159+
testNars(project(":pulsar-io:pulsar-io-data-generator"))
160+
testNars(project(":pulsar-io:pulsar-io-batch-data-generator"))
161+
testExamplesJar(project(":pulsar-functions:pulsar-functions-api-examples"))
162+
}
163+
144164
tasks.withType<Test> {
145-
dependsOn(
146-
":pulsar-functions:pulsar-functions-api-examples:jar",
147-
":pulsar-functions:pulsar-functions-api-examples-builtin:nar",
148-
":pulsar-io:pulsar-io-data-generator:nar",
149-
":pulsar-io:pulsar-io-batch-data-generator:nar",
150-
)
165+
dependsOn(testNars, testExamplesJar)
166+
val narFiles = testNars.incoming.artifacts.resolvedArtifacts
167+
val jarFiles = testExamplesJar.incoming.artifacts.resolvedArtifacts
151168
doFirst {
152-
fun narPath(projectPath: String): String {
153-
val p = rootProject.project(projectPath)
154-
return p.tasks.named("nar").get().outputs.files.singleFile.absolutePath
155-
}
156-
fun jarPath(projectPath: String): String {
157-
val p = rootProject.project(projectPath)
158-
return p.tasks.named<Jar>("jar").get().archiveFile.get().asFile.absolutePath
169+
val narMap = narFiles.get().associate {
170+
val id = it.id.componentIdentifier as org.gradle.api.artifacts.component.ProjectComponentIdentifier
171+
id.projectPath to it.file.absolutePath
159172
}
160-
val examplesJarPath = jarPath(":pulsar-functions:pulsar-functions-api-examples")
173+
val examplesJarPath = jarFiles.get().first().file.absolutePath
161174
systemProperty("pulsar-functions-api-examples.jar.path", examplesJarPath)
162-
systemProperty("pulsar-functions-api-examples.nar.path", narPath(":pulsar-functions:pulsar-functions-api-examples-builtin"))
163-
systemProperty("pulsar-io-data-generator.nar.path", narPath(":pulsar-io:pulsar-io-data-generator"))
164-
systemProperty("pulsar-io-batch-data-generator.nar.path", narPath(":pulsar-io:pulsar-io-batch-data-generator"))
175+
systemProperty("pulsar-functions-api-examples.nar.path",
176+
narMap[":pulsar-functions:pulsar-functions-api-examples-builtin"]!!)
177+
systemProperty("pulsar-io-data-generator.nar.path",
178+
narMap[":pulsar-io:pulsar-io-data-generator"]!!)
179+
systemProperty("pulsar-io-batch-data-generator.nar.path",
180+
narMap[":pulsar-io:pulsar-io-batch-data-generator"]!!)
165181
// A valid jar that is not a valid nar — used for invalid-nar tests
166182
systemProperty("pulsar-io-invalid.nar.path", examplesJarPath)
167183
}

pulsar-functions/worker/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ dependencies {
113113
}
114114

115115
tasks.withType<Test> {
116+
dependsOn(testNars, testExamplesJar)
116117
// Map resolved NAR/JAR files to system properties
117118
val narFiles = testNars.incoming.artifacts.resolvedArtifacts
118119
val jarFiles = testExamplesJar.incoming.artifacts.resolvedArtifacts

0 commit comments

Comments
 (0)