You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2026/04/17 07:16:36 UTC

(pulsar) branch master updated: [fix][broker] Avoid Project access in broker test setup (#25529)

This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new a4c291f6aa3 [fix][broker] Avoid Project access in broker test setup (#25529)
a4c291f6aa3 is described below

commit a4c291f6aa38c79a81396df9ab89259c0fca1aec
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Fri Apr 17 15:16:29 2026 +0800

    [fix][broker] Avoid Project access in broker test setup (#25529)
    
    Co-authored-by: Copilot <22...@users.noreply.github.com>
---
 pulsar-broker/build.gradle.kts           | 50 +++++++++++++++++++++-----------
 pulsar-functions/worker/build.gradle.kts |  1 +
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/pulsar-broker/build.gradle.kts b/pulsar-broker/build.gradle.kts
index d794da2325f..e82061e7022 100644
--- a/pulsar-broker/build.gradle.kts
+++ b/pulsar-broker/build.gradle.kts
@@ -141,27 +141,43 @@ evaluationDependsOn(":pulsar-io")
 evaluationDependsOn(":pulsar-functions")
 
 // NAR/JAR files needed by broker tests (mirrors Maven's maven-dependency-plugin config).
+// Resolve through dependency configurations instead of cross-project task references.
+val testNars by configurations.creating {
+    isCanBeResolved = true
+    isCanBeConsumed = false
+    attributes {
+        attribute(org.gradle.api.artifacts.type.ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "nar")
+    }
+}
+val testExamplesJar by configurations.creating {
+    isCanBeResolved = true
+    isCanBeConsumed = false
+}
+
+dependencies {
+    testNars(project(":pulsar-functions:pulsar-functions-api-examples-builtin"))
+    testNars(project(":pulsar-io:pulsar-io-data-generator"))
+    testNars(project(":pulsar-io:pulsar-io-batch-data-generator"))
+    testExamplesJar(project(":pulsar-functions:pulsar-functions-api-examples"))
+}
+
 tasks.withType<Test> {
-    dependsOn(
-        ":pulsar-functions:pulsar-functions-api-examples:jar",
-        ":pulsar-functions:pulsar-functions-api-examples-builtin:nar",
-        ":pulsar-io:pulsar-io-data-generator:nar",
-        ":pulsar-io:pulsar-io-batch-data-generator:nar",
-    )
+    dependsOn(testNars, testExamplesJar)
+    val narFiles = testNars.incoming.artifacts.resolvedArtifacts
+    val jarFiles = testExamplesJar.incoming.artifacts.resolvedArtifacts
     doFirst {
-        fun narPath(projectPath: String): String {
-            val p = rootProject.project(projectPath)
-            return p.tasks.named("nar").get().outputs.files.singleFile.absolutePath
-        }
-        fun jarPath(projectPath: String): String {
-            val p = rootProject.project(projectPath)
-            return p.tasks.named<Jar>("jar").get().archiveFile.get().asFile.absolutePath
+        val narMap = narFiles.get().associate {
+            val id = it.id.componentIdentifier as org.gradle.api.artifacts.component.ProjectComponentIdentifier
+            id.projectPath to it.file.absolutePath
         }
-        val examplesJarPath = jarPath(":pulsar-functions:pulsar-functions-api-examples")
+        val examplesJarPath = jarFiles.get().first().file.absolutePath
         systemProperty("pulsar-functions-api-examples.jar.path", examplesJarPath)
-        systemProperty("pulsar-functions-api-examples.nar.path", narPath(":pulsar-functions:pulsar-functions-api-examples-builtin"))
-        systemProperty("pulsar-io-data-generator.nar.path", narPath(":pulsar-io:pulsar-io-data-generator"))
-        systemProperty("pulsar-io-batch-data-generator.nar.path", narPath(":pulsar-io:pulsar-io-batch-data-generator"))
+        systemProperty("pulsar-functions-api-examples.nar.path",
+            narMap[":pulsar-functions:pulsar-functions-api-examples-builtin"]!!)
+        systemProperty("pulsar-io-data-generator.nar.path",
+            narMap[":pulsar-io:pulsar-io-data-generator"]!!)
+        systemProperty("pulsar-io-batch-data-generator.nar.path",
+            narMap[":pulsar-io:pulsar-io-batch-data-generator"]!!)
         // A valid jar that is not a valid nar — used for invalid-nar tests
         systemProperty("pulsar-io-invalid.nar.path", examplesJarPath)
     }
diff --git a/pulsar-functions/worker/build.gradle.kts b/pulsar-functions/worker/build.gradle.kts
index b233a4b0460..734dc9da0ae 100644
--- a/pulsar-functions/worker/build.gradle.kts
+++ b/pulsar-functions/worker/build.gradle.kts
@@ -113,6 +113,7 @@ dependencies {
 }
 
 tasks.withType<Test> {
+    dependsOn(testNars, testExamplesJar)
     // Map resolved NAR/JAR files to system properties
     val narFiles = testNars.incoming.artifacts.resolvedArtifacts
     val jarFiles = testExamplesJar.incoming.artifacts.resolvedArtifacts