Make gradle cache work when used from different locations
MODIFY
conventions/src/main/kotlin/otel.java-conventions.gradle.kts
conventions/src/main/kotlin/otel.java-conventions.gradle.kts
@@ -213,11 +213,9 @@ tasks.withType<Test>().configureEach {
jvmArgs("-Dotel.java.disabled.resource.providers=${resourceClassesCsv}")
val trustStore = project(":testing-common").file("src/misc/testing-keystore.p12")
- inputs.file(trustStore)
// Work around payara not working when this is set for some reason.
if (project.name != "jaxrs-2.0-payara-testing") {
- jvmArgs("-Djavax.net.ssl.trustStore=${trustStore.absolutePath}")
- jvmArgs("-Djavax.net.ssl.trustStorePassword=testing")
+ jvmArgumentProviders.add(KeystoreArgumentsProvider(trustStore))
}
// All tests must complete within 15 minutes.
@@ -238,6 +236,16 @@ tasks.withType<Test>().configureEach {
}
}
+class KeystoreArgumentsProvider(
+ @InputFile
+ @PathSensitive(PathSensitivity.RELATIVE)
+ val trustStore: File
+) : CommandLineArgumentProvider {
+ override fun asArguments(): Iterable<String> = listOf(
+ "-Djavax.net.ssl.trustStore=${trustStore.absolutePath}",
+ "-Djavax.net.ssl.trustStorePassword=testing")
+}
+
afterEvaluate {
val testJavaVersion = gradle.startParameter.projectProperties["testJavaVersion"]?.let(JavaVersion::toVersion)
val useJ9 = gradle.startParameter.projectProperties["testJavaVM"]?.run { this == "openj9" }

MODIFY
gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts
gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts
@@ -64,7 +64,7 @@ tasks {
fun createLanguageTask(
compileTaskProvider: TaskProvider<*>, name: String): TaskProvider<*> {
- return tasks.register<ByteBuddySimpleTask>(name) {
+ return tasks.register<ByteBuddyTask>(name) {
setGroup("Byte Buddy")
outputs.cacheIf { true }
var transformationClassPath = inputClasspath
@@ -91,3 +91,12 @@ fun createTransformation(classPath: FileCollection, pluginClassName: String): Tr
plugin = ClasspathByteBuddyPlugin::class.java
}
}
+
+//TODO remove when https://github.com/raphw/byte-buddy/issues/1169 is fixed
+open class ByteBuddyTask : ByteBuddySimpleTask() {
+ @InputDirectory
+ @PathSensitive(PathSensitivity.RELATIVE)
+ override fun getSource(): File? {
+ return super.getSource()
+ }
+}

MODIFY
instrumentation/gwt-2.0/javaagent/build.gradle.kts
instrumentation/gwt-2.0/javaagent/build.gradle.kts
@@ -45,38 +45,38 @@ dependencies {
testImplementation("org.eclipse.jetty:jetty-webapp:9.4.35.v20201120")
}
-val warDir = "$buildDir/testapp/war"
+val warDir = file("$buildDir/testapp/war")
val launcher = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(8))
}
+class CompilerArgumentsProvider : CommandLineArgumentProvider {
+ override fun asArguments(): Iterable<String> = listOf(
+ "test.gwt.Greeting", // gwt module
+ "-war", "$buildDir/testapp/war",
+ "-logLevel", "INFO",
+ "-localWorkers", "2",
+ "-compileReport",
+ "-extra", "$buildDir/testapp/extra",
+ "-draftCompile" // makes compile a bit faster
+ )
+}
+
tasks {
val compileGwt by registering(JavaExec::class) {
dependsOn(classes)
// versions before 2.9 require java8
javaLauncher.set(launcher)
- val extraDir = "$buildDir/testapp/extra"
-
outputs.cacheIf { true }
-
- outputs.dir(extraDir)
outputs.dir(warDir)
mainClass.set("com.google.gwt.dev.Compiler")
classpath(sourceSets["testapp"].java.srcDirs, sourceSets["testapp"].compileClasspath)
- args(
- "test.gwt.Greeting", // gwt module
- "-war", warDir,
- "-logLevel", "INFO",
- "-localWorkers", "2",
- "-compileReport",
- "-extra", extraDir,
- "-draftCompile" // makes compile a bit faster
- )
+ argumentProviders.add(CompilerArgumentsProvider())
}
val copyTestWebapp by registering(Copy::class) {

MODIFY
javaagent/build.gradle.kts
javaagent/build.gradle.kts
@@ -228,14 +228,10 @@ tasks {
withType<Test>().configureEach {
dependsOn(shadowJar)
- inputs.file(shadowJar.get().archiveFile)
jvmArgs("-Dotel.javaagent.debug=true")
- doFirst {
- // Defining here to allow jacoco to be first on the command line.
- jvmArgs("-javaagent:${shadowJar.get().archiveFile.get().asFile}")
- }
+ jvmArgumentProviders.add(JavaagentProvider(shadowJar.flatMap { it.archiveFile }))
testLogging {
events("started")
@@ -299,3 +295,13 @@ fun ShadowJar.excludeBootstrapJars() {
exclude(project(":javaagent-instrumentation-api"))
}
}
+
+class JavaagentProvider(
+ @InputFile
+ @PathSensitive(PathSensitivity.RELATIVE)
+ val agentJar: Provider<RegularFile>
+) : CommandLineArgumentProvider {
+ override fun asArguments(): Iterable<String> = listOf(
+ "-javaagent:${file(agentJar).absolutePath}"
+ )
+}

MODIFY
testing/agent-for-testing/build.gradle.kts
testing/agent-for-testing/build.gradle.kts
@@ -43,11 +43,20 @@ tasks {
afterEvaluate {
withType<Test>().configureEach {
- dependsOn(jar)
-
jvmArgs("-Dotel.javaagent.debug=true")
- jvmArgs("-javaagent:${jar.get().archiveFile.get().asFile.absolutePath}")
jvmArgs("-Dotel.metrics.exporter=otlp")
+
+ jvmArgumentProviders.add(JavaagentProvider(jar.flatMap { it.archiveFile }))
+ }
}
}
+
+class JavaagentProvider(
+ @InputFile
+ @PathSensitive(PathSensitivity.RELATIVE)
+ val agentJar: Provider<RegularFile>
+) : CommandLineArgumentProvider {
+ override fun asArguments(): Iterable<String> = listOf(
+ "-javaagent:${file(agentJar).absolutePath}"
+ )
}

Make gradle cache work when used from different locations (#4794)