From 24d0a7094cc2fbde3eaa958885c22f54bf22c2e0 Mon Sep 17 00:00:00 2001 From: Brice Dutheil Date: Thu, 16 Jul 2026 18:13:06 +0200 Subject: [PATCH 1/2] chore(gradle): remove datanucleus buildscript block Load the DataNucleus enhancer from a dedicated project configuration instead of the script classpath. This keeps the enhancer dependencies in the normal dependency model and resolves them only when the enhance task runs. Also, this project already gets repository setup from the shared Java build scripts. --- .../datanucleus-4.0.5/build.gradle | 51 ++++++++----------- .../datanucleus-4.0.5/gradle.lockfile | 8 +-- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle b/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle index 4fb501a01ab..d440e52111b 100644 --- a/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle +++ b/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle @@ -1,24 +1,3 @@ -import org.datanucleus.enhancer.DataNucleusEnhancer - -buildscript { - repositories { - mavenLocal() - if (project.rootProject.hasProperty("mavenRepositoryProxy")) { - maven { - url project.rootProject.property("mavenRepositoryProxy") - allowInsecureProtocol = true - } - } - mavenCentral() - } - - dependencies { - classpath group: 'org.datanucleus', name: 'datanucleus-core', version: '4.0.5' - classpath group: 'org.datanucleus', name: 'datanucleus-api-jdo', version: '4.0.5' - classpath group: 'org.datanucleus', name: 'javax.jdo', version: '3.2.0-m1' - } -} - muzzle { // 2 libraries are instrumented. // Muzzle is tested by keeping one version fixed and modifying the other @@ -44,24 +23,34 @@ apply from: "${rootDir}/gradle/java.gradle" def datanucleusVersion = '4.0.5' +def datanucleusEnhancer = configurations.register("datanucleusEnhancer") { + canBeConsumed = false + canBeResolved = true +} + // Datanucleus modifies persistable objects with bytecode manipulation // The unofficial plugin (org.rm3l.datanucleus-gradle-plugin) doesn't work with our build // The enhancement is done manually here for the test classes // LatestDepTest can't be used because the enhancer class generates incompatible code // Specifically, org.datanucleus.enhancer.Persistable changes package -// Only one version can be set as the script classpath in the 'buildScript' block tasks.register('enhance') { doLast { - def outputUrls = (sourceSets.test.output.classesDirs.files + sourceSets.test.output.resourcesDir) + def outputUrls = (datanucleusEnhancer.get().files + sourceSets.test.output.classesDirs.files + sourceSets.test.output.resourcesDir) + .findAll { it != null } .collect { it.toURI().toURL() } as URL[] def testClassloader = new URLClassLoader(outputUrls, Thread.currentThread().getContextClassLoader()) - - DataNucleusEnhancer enhancer = new DataNucleusEnhancer("JDO", null) - enhancer.setVerbose(true).addPersistenceUnit("testPersistenceUnit") - enhancer.setSystemOut(true) - enhancer.setClassLoader(testClassloader) - enhancer.enhance() + try { + def enhancerClass = testClassloader.loadClass("org.datanucleus.enhancer.DataNucleusEnhancer") + enhancerClass.getConstructor(String, Properties).newInstance("JDO", null).with { + setVerbose(true).addPersistenceUnit("testPersistenceUnit") + setSystemOut(true) + setClassLoader(testClassloader) + enhance() + } + } finally { + testClassloader.close() + } } dependsOn "testClasses" @@ -82,4 +71,8 @@ dependencies { testImplementation group: 'org.datanucleus', name: 'datanucleus-rdbms', version: datanucleusVersion testImplementation group: 'org.datanucleus', name: 'javax.jdo', version: '3.2.0-m1' testImplementation group: 'com.h2database', name: 'h2', version: '1.3.169' + + add(datanucleusEnhancer.name, "org.datanucleus:datanucleus-core:$datanucleusVersion") + add(datanucleusEnhancer.name, "org.datanucleus:datanucleus-api-jdo:$datanucleusVersion") + add(datanucleusEnhancer.name, "org.datanucleus:javax.jdo:3.2.0-m1") } diff --git a/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile b/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile index f32c0056e9a..6f56c5a195b 100644 --- a/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile +++ b/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile @@ -54,7 +54,7 @@ de.thetaphi:forbiddenapis:3.10=compileClasspath,testCompileClasspath,testRuntime io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath io.sqreen:libsqreen:17.3.0=testRuntimeClasspath javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath -javax.transaction:transaction-api:1.1=compileClasspath,testCompileClasspath,testRuntimeClasspath +javax.transaction:transaction-api:1.1=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath jaxen:jaxen:2.0.0=spotbugs junit:junit:4.13.2=testRuntimeClasspath net.bytebuddy:byte-buddy-agent:1.18.10=buildTimeInstrumentationPlugin,compileClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath @@ -81,10 +81,10 @@ org.codehaus.groovy:groovy-xml:3.0.23=codenarc org.codehaus.groovy:groovy:3.0.23=codenarc org.codehaus.groovy:groovy:3.0.25=testCompileClasspath,testRuntimeClasspath org.codenarc:CodeNarc:3.7.0=codenarc -org.datanucleus:datanucleus-api-jdo:4.0.5=compileClasspath,testCompileClasspath,testRuntimeClasspath -org.datanucleus:datanucleus-core:4.0.5=compileClasspath,testCompileClasspath,testRuntimeClasspath +org.datanucleus:datanucleus-api-jdo:4.0.5=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath +org.datanucleus:datanucleus-core:4.0.5=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath org.datanucleus:datanucleus-rdbms:4.0.5=testCompileClasspath,testRuntimeClasspath -org.datanucleus:javax.jdo:3.2.0-m1=compileClasspath,testCompileClasspath,testRuntimeClasspath +org.datanucleus:javax.jdo:3.2.0-m1=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath org.dom4j:dom4j:2.2.0=spotbugs org.gmetrics:GMetrics:2.1.0=codenarc org.hamcrest:hamcrest-core:1.3=testRuntimeClasspath From 275ddc0ec3aac8fae0a7545c179be551cbaabde5 Mon Sep 17 00:00:00 2001 From: Brice Dutheil Date: Thu, 16 Jul 2026 18:13:59 +0200 Subject: [PATCH 2/2] chore(gradle): remove forbidden-apis buildscript block The root build already declares the forbidden-apis plugin version. Reuse that plugin declaration from the shared script instead of carrying a second script-level classpath and repository setup. --- gradle/forbiddenapis.gradle | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/gradle/forbiddenapis.gradle b/gradle/forbiddenapis.gradle index 4318766c9ac..788d5b1b979 100644 --- a/gradle/forbiddenapis.gradle +++ b/gradle/forbiddenapis.gradle @@ -1,27 +1,3 @@ -buildscript { - repositories { - mavenLocal() - if (project.rootProject.hasProperty("gradlePluginProxy")) { - maven { - url project.rootProject.property("gradlePluginProxy") - allowInsecureProtocol = true - } - } - if (project.rootProject.hasProperty("mavenRepositoryProxy")) { - maven { - url project.rootProject.property("mavenRepositoryProxy") - allowInsecureProtocol = true - } - } - gradlePluginPortal() - mavenCentral() - } - - dependencies { - classpath libs.forbiddenapis - } -} - apply plugin: "de.thetaphi.forbiddenapis" def mainFilterFile = files("$rootDir/gradle/forbiddenApiFilters/main.txt")