Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions buildSrc/src/main/groovy/InstrumentPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,16 @@ abstract class InstrumentTask extends DefaultTask {
}

private workQueue() {
if (this.javaVersion) {
def javaLauncher = this.javaToolchainService.launcherFor { spec ->
spec.languageVersion.set(JavaLanguageVersion.of(this.javaVersion))
}.get()
return this.workerExecutor.processIsolation { spec ->
spec.forkOptions { fork ->
fork.executable = javaLauncher.executablePath
}
if (!this.javaVersion) {
this.javaVersion = "8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Maybe extract "8" to some variable indicating the agent version.

Another suggestion: wouldn't be better to set 8 as a default value in MuzzleDirective.javaVersion ?

}
def javaLauncher = this.javaToolchainService.launcherFor { spec ->
spec.languageVersion.set(JavaLanguageVersion.of(this.javaVersion))
}.get()
return this.workerExecutor.processIsolation { spec ->
spec.forkOptions { fork ->
fork.executable = javaLauncher.executablePath
}
} else {
return this.workerExecutor.noIsolation()
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions buildSrc/src/main/groovy/MuzzlePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -715,18 +715,14 @@ abstract class MuzzleTask extends DefaultTask {
Project instrumentationProject,
MuzzleDirective muzzleDirective = null) {
def workQueue
String javaVersion = muzzleDirective?.javaVersion
if (javaVersion) {
def javaLauncher = javaToolchainService.launcherFor { spec ->
spec.languageVersion.set(JavaLanguageVersion.of(javaVersion))
}.get()
workQueue = workerExecutor.processIsolation { spec ->
spec.forkOptions { fork ->
fork.executable = javaLauncher.executablePath
}
String javaVersion = muzzleDirective?.javaVersion ?: "8"
def javaLauncher = javaToolchainService.launcherFor { spec ->
spec.languageVersion.set(JavaLanguageVersion.of(javaVersion))
}.get()
workQueue = workerExecutor.processIsolation { spec ->
spec.forkOptions { fork ->
fork.executable = javaLauncher.executablePath
}
} else {
workQueue = workerExecutor.noIsolation()
Comment on lines +722 to -729
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: After some diving, the ClassLoader.systemClassLoader() in workerExecutor.processIsolation(...) work queue appears to have quite a few jars from the gradle distribution — 165 on minimal reproducer project with gradle 8.14.2 — on the classpath.

Among them httpclient 4.5.13, which may explains why some muzzle tests (like :dd-java-agent:instrumentation:apache-httpclient-4:muzzle-AssertFail-commons-httpclient-commons-httpclient-3.1) are succeeding instead of failing. These are checking that dependencies outside this range [4.0,5) do not match, but during lookup class of the httpclient are seen on the classpath.

image

This does not happen when the work queue executor workerExecutor.noIsolation() was used. It was used when the javaVersion was not explictly set via the coreJdk() muzzle directive. In fact in this mode the ClassLoader.systemCLassLoader() shows only two gradle jars, the gradle launcher and the instrumentation agent.


We may want to improve the situation there, as it renders the tests brittle even if they appear to rightfully pass.

For this PR, which is about decoupling the JDK running gradle from the target JDK (8 at this time), we may possibly run this in the JVM that runs gradle because muzzle is about detecting whether a dependency is still covered by an instrumentation and as such tries to detect types / "outlines".

Copy link
Contributor

@bric3 bric3 Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, here's how to debug,

  1. First select only one version that fails, e.g. the directive that is failing is pass with a range assertInverse (this will assess that opposite range will fail), so we need a directive expected to fail for a single version, e.g. here expect 3.1 to fail.

      muzzle {
    -   fail {
    -     group = "commons-httpclient"
    -     module = "commons-httpclient"
    -     versions = "[,4.0)"
    -     skipVersions += '3.1-jenkins-1'
    -     skipVersions += '2.0-final' // broken metadata on maven central
    -   }
    -   pass {
    -     group = "org.apache.httpcomponents"
    -     module = "httpclient"
    -     versions = "[4.0,5)"
    -     assertInverse = true
    -   }
    -   pass {
    -     // We want to support the dropwizard clients too.
    -     group = 'io.dropwizard'
    -     module = 'dropwizard-client'
    -     versions = "[,3)" // dropwizard-client 3+ uses httpclient5
    -   }
    +   fail {
    +     group = "commons-httpclient"
    +     module = "commons-httpclient"
    +     versions = "[3.1,]"
    +   }
      }

    This is necessary because the task :dd-java-agent:instrumentation:apache-httpclient-4:muzzle-AssertFail-commons-httpclient-commons-httpclient-3.1 is created after invoking muzzle, and as such cannot be invoked directly.

  2. Make the worker daemon debuggable since it's another process

      workQueue = workerExecutor.processIsolation { spec ->
        spec.forkOptions { fork ->
          fork.executable = javaLauncher.executablePath
    +       fork.debug = true
        }
      }
  3. Then run/debug the muzzle task :dd-java-agent:instrumentation:apache-httpclient-4:muzzle.

  4. When the daemon work prints it's listening for a debugger, just click the Attach debugger inline action.

    image

    Or manually create a Remote JVM Debug config in Intellij in Attach to remote JVM debugger mode. Other settings are untouched (port in 5005). No need to add the command line arg to the forked process !

}
workQueue.submit(MuzzleAction.class, parameters -> {
parameters.buildStartedTime.set(invocationDetails.buildStartedTime)
Expand Down
10 changes: 5 additions & 5 deletions dd-java-agent/agent-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ plugins {
id 'me.champeau.jmh'
}

ext {
// need access to sun.* packages
skipSettingCompilerRelease = true
}

apply from: "$rootDir/gradle/java.gradle"
apply plugin: "idea"

tasks.named("compileJava", JavaCompile).configure {
// need access to sun.* packages
setJavaVersion(it, 8)
}

// FIXME: Improve test coverage.
minimumBranchCoverage = 0.0
minimumInstructionCoverage = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ ext {
// By default tests with be compiled for `minJavaVersionForTests` version,
// but in this case we would like to avoid this since we would like to run with ZULU8
skipSettingTestJavaVersion = true
// need access to jdk.jfr package
skipSettingCompilerRelease = true
excludeJdk = ['SEMERU11', 'SEMERU17']
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ ext {
// of ByteBuffer.position(int) which is binary incompatible with Java 8 ¯\_(ツ)_/¯
minJavaVersionForTests = JavaVersion.VERSION_11

// need access to jdk.jfr package
skipSettingCompilerRelease = true

excludeJdk = ['SEMERU11', 'SEMERU17']
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8

// need access to jdk.jfr package
skipSettingCompilerRelease = true
}

apply from: "$rootDir/gradle/java.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ ext {
// By default tests with be compiled for `minJavaVersionForTests` version,
// but in this case we would like to avoid this since we would like to run with ZULU8
skipSettingTestJavaVersion = true
// need access to jdk.jfr package
skipSettingCompilerRelease = true
}

apply from: "$rootDir/gradle/java.gradle"
Expand Down Expand Up @@ -39,6 +37,10 @@ dependencies {
[JavaCompile, GroovyCompile].each {
tasks.withType(it).configureEach {
setJavaVersion(it, 11)
if (it instanceof JavaCompile) {
// need access to jdk.jfr package
options.release = null
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
// Disable '-processing' because some annotations are not claimed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ ext {
// By default tests with be compiled for `minJavaVersionForTests` version,
// but in this case we would like to avoid this since we would like to run with ORACLE8
skipSettingTestJavaVersion = true
// need access to jdk.jfr package
skipSettingCompilerRelease = true
}

apply from: "$rootDir/gradle/java.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ muzzle {
}
}

ext {
skipSettingCompilerRelease = true
}
apply from: "${rootDir}/gradle/java.gradle"

compileJava {
Expand Down
1 change: 1 addition & 0 deletions dd-java-agent/instrumentation/mule-4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ tasks.register('extractLatestMuleServices', Sync) {
// build the mule application via maven
tasks.register('mvnPackage', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Wouldn't be better to derive this env var from the toolchain API ?

Same for the other similar changes.

commandLine "$rootDir/mvnw", "-Ddatadog.builddir=$buildDir", "-Ddatadog.name=mule-test-application", "-Ddatadog.version=$version", 'package'
outputs.dir("$buildDir/target")
inputs.dir("$appDir/src")
Expand Down
7 changes: 5 additions & 2 deletions dd-java-agent/instrumentation/rmi/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
ext {
// need access to sun.rmi package
skipSettingCompilerRelease = true
// TODO Java 17: The necessary packages are not opened on Java 17
maxJavaVersionForTests = JavaVersion.VERSION_15
}
Expand All @@ -13,6 +11,11 @@ muzzle {

apply from: "$rootDir/gradle/java.gradle"

tasks.withType(JavaCompile).configureEach {
// need access to sun.rmi package
setJavaVersion(it, 8)
}

def rmic = tasks.register('rmic', Exec) {
dependsOn testClasses

Expand Down
8 changes: 4 additions & 4 deletions dd-java-agent/testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ plugins {
id 'com.gradleup.shadow'
}

ext {
apply from: "$rootDir/gradle/java.gradle"

tasks.withType(JavaCompile).configureEach {
// need access to sun.misc package
skipSettingCompilerRelease = true
setJavaVersion(it, 8)
}

apply from: "$rootDir/gradle/java.gradle"

minimumBranchCoverage = 0.5
minimumInstructionCoverage = 0.5
excludedClassesCoverage += [
Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/quarkus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('quarkusBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "${rootDir}/${gradlewCommand}", "build", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/spring-boot-2.7-webflux/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('webfluxBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "$rootDir/${gradlewCommand}", "bootJar", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/springboot-openliberty-20/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def mvnwCommand = isWindows ? 'mvnw.cmd' : 'mvnw'
// compile the Open liberty spring boot server
tasks.register('mvnStage', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
commandLine "$rootDir/${mvnwCommand}", 'package', "-Dtarget.dir=${buildDir}/application/target"
inputs.dir "$appDir/src"
inputs.file "$appDir/pom.xml"
Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/springboot-openliberty-23/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def mvnwCommand = isWindows ? 'mvnw.cmd' : 'mvnw'
// compile the Open liberty spring boot server
tasks.register('mvnStage', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
commandLine "$rootDir/${mvnwCommand}", 'package', "-Dtarget.dir=${buildDir}/application/target"
inputs.dir "$appDir/src"
inputs.file "$appDir/pom.xml"
Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/vertx-3.4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('vertxBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "$appDir/${gradlewCommand}", "assemble", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/vertx-3.9-resteasy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('vertxBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "$appDir/${gradlewCommand}", "assemble", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/vertx-3.9/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('vertxBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "$appDir/${gradlewCommand}", "assemble", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/vertx-4.2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('vertxBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "$appDir/${gradlewCommand}", "assemble", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/wildfly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def gradlewCommand = isWindows ? 'gradlew.bat' : 'gradlew'
// define the task that builds the quarkus project
tasks.register('earBuild', Exec) {
workingDir "$appDir"
environment.JAVA_HOME = System.getenv("JAVA_8_HOME")
environment += ["GRADLE_OPTS": "-Dorg.gradle.jvmargs='-Xmx512M'"]
commandLine "$rootDir/${gradlewCommand}", "assemble", "--no-daemon", "--max-workers=4", "-PappBuildDir=$appBuildDir", "-PapiJar=${project(':dd-trace-api').tasks.jar.archiveFile.get()}"

Expand Down
20 changes: 9 additions & 11 deletions gradle/java_no_deps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import org.gradle.jvm.toolchain.internal.SpecificInstallationToolchainSpec

apply plugin: 'java-library'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

apply from: "$rootDir/gradle/codenarc.gradle"
apply from: "$rootDir/gradle/forbiddenapis.gradle"
apply from: "$rootDir/gradle/spotless.gradle"
Expand Down Expand Up @@ -34,17 +43,6 @@ if (applyCodeCoverage) {
apply from: "$rootDir/gradle/jacoco.gradle"
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

// when building with Java 9+, lazily set compiler --release flag to match target
def skipSettingCompilerRelease = project.findProperty('skipSettingCompilerRelease')
if (!skipSettingCompilerRelease && JavaVersion.current().isJava9Compatible()) {
compileJava.options.release = project.provider {
JavaVersion.toVersion(targetCompatibility).majorVersion as Integer
}
}
Comment on lines -41 to -46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I'd suggest to keep this behavior via ext.setJavaVersion, dropping the flag skipSettingCompilerRelease and just use the release options if JDK >= 9.

Possible the setJavaVersion, can have a flag or enum that could be used to explicitly use the source and target rather than option, e.g. for the profiling project to access jfr.


if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJavaVersionForTests') != JavaVersion.VERSION_1_7) {
def version = JavaVersion.toVersion(project.getProperty('minJavaVersionForTests'))
def name = "java$version.majorVersion"
Expand Down
15 changes: 2 additions & 13 deletions internal-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ plugins {
id 'me.champeau.jmh'
}

ext {
// need access to sun.misc.SharedSecrets
skipSettingCompilerRelease = true
}

// sun.misc.SharedSecrets is gone in later versions
compileJava {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(8)
}
}

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/tries.gradle"

tasks.compileTestJava.configure {
tasks.withType(JavaCompile).configureEach {
// need access to sun.misc.SharedSecrets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

Suggested change
// need access to sun.misc.SharedSecrets
// Need access to sun.misc.SharedSecrets, which moved to a restricted jdk module in later JDKs

setJavaVersion(it, 8)
}

Expand Down