Skip to content

Enable Gradle configuration caching #14293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ plugins {
* The latest *released* version of the project. Evaluated lazily so the work is only done if necessary.
*/
val latestReleasedVersion: String by lazy {
// hack to find the current released version of the project
val temp: Configuration = configurations.create("tempConfig")
temp.resolutionStrategy.cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
// pick the bom, since we don't use dependency substitution on it.
dependencies.add(temp.name, "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:latest.release")
val moduleVersion = configurations["tempConfig"].resolvedConfiguration.firstLevelModuleDependencies.elementAt(0).moduleVersion

configurations.remove(temp)
logger.info("Discovered latest release version: $moduleVersion")
moduleVersion
"2.18.0"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ val languageTasks = LANGUAGES.map { language ->
return@map null
}
val compileTask = tasks.named(compileTaskName)
createLanguageTask(compileTask, "byteBuddy${language.replaceFirstChar(Char::titlecase)}")
createLanguageTask(compileTask, language)
}.filterNotNull()

tasks {
Expand All @@ -60,29 +60,43 @@ tasks {
}

fun createLanguageTask(
compileTaskProvider: TaskProvider<*>, name: String): TaskProvider<*> {
return tasks.register<ByteBuddySimpleTask>(name) {
setGroup("Byte Buddy")
outputs.cacheIf { true }
classFileVersion = ClassFileVersion.JAVA_V8
var transformationClassPath = inputClasspath
compileTaskProvider: TaskProvider<*>, language: String): TaskProvider<*> {
val taskName = "byteBuddy${language.replaceFirstChar { it.uppercase() }}"
val mainSourceSet = sourceSets.main.get()
val projectName = project.name

// Create the input classpath from the existing logic in the main part
val inputClasspath = (mainSourceSet.output.resourcesDir?.let { codegen.plus(project.files(it)) }
?: codegen)
.plus(mainSourceSet.output.dirs) // needed to support embedding shadowed modules into instrumentation
.plus(configurations.runtimeClasspath.get())

val byteBuddyTask = tasks.register(taskName, ByteBuddySimpleTask::class.java) {
dependsOn(compileTaskProvider, mainSourceSet.processResourcesTaskName)

transformations.add(createTransformation(inputClasspath, projectName))

// Configure the ByteBuddy task properties directly during task creation
val compileTask = compileTaskProvider.get()
// this does not work for kotlin as compile task does not extend AbstractCompile
if (compileTask is AbstractCompile) {
val classesDirectory = compileTask.destinationDirectory.asFile.get()
val rawClassesDirectory: File = File(classesDirectory.parent, "${classesDirectory.name}raw")
.absoluteFile
dependsOn(compileTask)
val rawClassesDirectory = File(classesDirectory.parent, "${classesDirectory.name}raw").absoluteFile

// Configure the compile task to write to rawClassesDirectory
compileTask.destinationDirectory.set(rawClassesDirectory)

// Configure ByteBuddy task properties
source = rawClassesDirectory
target = classesDirectory
classPath = compileTask.classpath.plus(rawClassesDirectory)
transformationClassPath = transformationClassPath.plus(files(rawClassesDirectory))
dependsOn(compileTask, sourceSet.processResourcesTaskName)

// Clear and set transformations with correct classpath
transformations.clear()
transformations.add(createTransformation(inputClasspath.plus(files(rawClassesDirectory)), pluginName))
}

transformations.add(createTransformation(transformationClassPath, pluginName))
}

return byteBuddyTask
}

fun createTransformation(classPath: FileCollection, pluginClassName: String): Transformation {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true

org.gradle.priority=low

Expand Down
54 changes: 51 additions & 3 deletions instrumentation-api-incubator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
plugins {
id("org.xbib.gradle.plugin.jflex")

id("otel.java-conventions")
id("otel.animalsniffer-conventions")
id("otel.jacoco-conventions")
Expand All @@ -10,7 +8,18 @@ plugins {

group = "io.opentelemetry.instrumentation"

// JFlex configuration - manual integration for configuration cache compatibility
configurations {
val jflex by creating {
isTransitive = true
}
}

dependencies {
"jflex"("de.jflex:jflex:1.9.1")
"jflex"("com.github.vbmacher:java-cup-runtime:11b-20160615")

api("io.opentelemetry.semconv:opentelemetry-semconv")
api("io.opentelemetry.semconv:opentelemetry-semconv")
api(project(":instrumentation-api"))
api("io.opentelemetry:opentelemetry-api-incubator")
Expand All @@ -24,6 +33,41 @@ dependencies {
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
}

// Manual JFlex task - configuration cache compatible
val generateJflex by tasks.registering(JavaExec::class) {
description = "Generate Java code from JFlex files"
group = "build"

classpath = configurations.getByName("jflex")
mainClass.set("jflex.Main")

val jflexSourceDir = file("src/main/jflex")
val jflexOutputDir = file("build/generated/sources/jflex")

inputs.dir(jflexSourceDir)
outputs.dir(jflexOutputDir)

doFirst {
jflexOutputDir.mkdirs()
}

args(
"-d", jflexOutputDir,
"--nobak",
"$jflexSourceDir/SqlSanitizer.jflex"
)
}

sourceSets {
main {
java.srcDir(generateJflex.map { it.outputs.files.singleFile })
}
}

tasks.compileJava {
dependsOn(generateJflex)
}

tasks {
// exclude auto-generated code
named<Checkstyle>("checkstyleMain") {
Expand All @@ -38,7 +82,11 @@ tasks {
}

sourcesJar {
dependsOn("generateJflex")
dependsOn(generateJflex)
// Avoid configuration cache issue by not capturing task reference
from("src/main/jflex") {
include("**/*.java")
}
}

val testStableSemconv by registering(Test::class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
plugins {
id("org.unbroken-dome.xjc")
id("otel.java-conventions")
}

// Configuration for XJC code generation
val xjcTool by configurations.creating

val generateXjcSources = tasks.register<JavaExec>("generateXjcSources") {
val schemaDir = file("src/main/schema")
val outputDir = layout.buildDirectory.dir("generated/sources/xjc/java/main").get().asFile

inputs.dir(schemaDir)
outputs.dir(outputDir)

classpath = xjcTool
mainClass.set("com.sun.tools.xjc.XJCFacade")

args(
"-d",
outputDir.absolutePath,
"-p",
"io.opentelemetry.test.hello_web_service",
file("$schemaDir/hello.xsd").absolutePath
)

doFirst {
outputDir.mkdirs()
}
}

sourceSets {
main {
java {
srcDir(generateXjcSources.map { it.outputs.files.singleFile })
}
}
}

tasks.compileJava {
dependsOn(generateXjcSources)
}

tasks {
named<Checkstyle>("checkstyleMain") {
// exclude generated web service classes
Expand All @@ -18,4 +55,9 @@ dependencies {
api("org.springframework.ws:spring-ws-core:3.0.0.RELEASE")

implementation(project(":testing-common"))

// XJC tool dependencies
xjcTool("com.sun.xml.bind:jaxb-xjc:2.3.3")
xjcTool("com.sun.xml.bind:jaxb-impl:2.3.3")
xjcTool("com.sun.xml.bind:jaxb-core:2.3.0.1")
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
plugins {
id("org.unbroken-dome.xjc")
id("otel.java-conventions")
}

// Configuration for XJC code generation
val xjcTool by configurations.creating

val generateXjcSources = tasks.register<JavaExec>("generateXjcSources") {
val schemaDir = file("src/main/schema")
val outputDir = layout.buildDirectory.dir("generated/sources/xjc/java/main").get().asFile

inputs.dir(schemaDir)
outputs.dir(outputDir)

classpath = xjcTool
mainClass.set("com.sun.tools.xjc.XJCFacade")

args(
"-d",
outputDir.absolutePath,
"-p",
"io.opentelemetry.test.hello_web_service",
file("$schemaDir/hello.xsd").absolutePath
)

doFirst {
outputDir.mkdirs()
}
}

sourceSets {
main {
java {
srcDir(generateXjcSources.map { it.outputs.files.singleFile })
}
}
}

tasks.compileJava {
dependsOn(generateXjcSources)
}

tasks {
named<Checkstyle>("checkstyleMain") {
// exclude generated web service classes
Expand All @@ -19,6 +56,7 @@ dependencies {

implementation(project(":testing-common"))

// XJC tool dependencies (using Jakarta/JAXB 3.0)
xjcTool("com.sun.xml.bind:jaxb-xjc:3.0.2")
xjcTool("com.sun.xml.bind:jaxb-impl:3.0.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ tasks.named("checkstyleTest").configure {
tasks.named("compileTestJava").configure {
dependsOn(tasks.named("compileQuarkusTestGeneratedSourcesJava"))
}

tasks.configureEach {
notCompatibleWithConfigurationCache("TODO")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ tasks.named("compileJava").configure {
tasks.named("sourcesJar").configure {
dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava"))
}

tasks.configureEach {
notCompatibleWithConfigurationCache("TODO")
}
55 changes: 46 additions & 9 deletions instrumentation/spring/spring-ws-2.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
plugins {
id("org.unbroken-dome.xjc")
id("otel.javaagent-instrumentation")
}

muzzle {
pass {
group.set("org.springframework.ws")
module.set("spring-ws-core")
versions.set("[2.0.0.RELEASE,]")
// broken versions, jars don't contain classes
skip("3.0.11.RELEASE", "3.1.0")
assertInverse.set(true)
// Configuration for XJC code generation
val xjcTool by configurations.creating

val generateXjcSources = tasks.register<JavaExec>("generateXjcSources") {
val schemaDir = file("src/test/schema")
val outputDir = layout.buildDirectory.dir("generated/sources/xjc/java/test").get().asFile

inputs.dir(schemaDir)
outputs.dir(outputDir)

classpath = xjcTool
mainClass.set("com.sun.tools.xjc.XJCFacade")

args(
"-d",
outputDir.absolutePath,
"-p",
"io.opentelemetry.test.hello_web_service",
file("$schemaDir/hello.xsd").absolutePath
)

doFirst {
outputDir.mkdirs()
}
}

sourceSets {
test {
java {
srcDir(generateXjcSources.map { it.outputs.files.singleFile })
}
resources {
srcDirs("src/test/schema")
}
}
}

tasks.compileTestJava {
dependsOn(generateXjcSources)
}

muzzle {
pass {
group.set("org.springframework.ws")
module.set("spring-ws-core")
versions.set("[2.0.0.RELEASE,]")
// broken versions, jars don't contain classes
skip("3.0.11.RELEASE", "3.1.0")
assertInverse.set(true)
}
}

tasks {
named<Checkstyle>("checkstyleTest") {
// exclude generated web service classes
Expand Down Expand Up @@ -49,6 +81,11 @@ dependencies {
testImplementation("com.google.guava:guava")

testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))

// XJC tool dependencies
xjcTool("com.sun.xml.bind:jaxb-xjc:2.3.3")
xjcTool("com.sun.xml.bind:jaxb-impl:2.3.3")
xjcTool("com.sun.xml.bind:jaxb-core:2.3.0.1")
}

tasks.withType<Test>().configureEach {
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pluginManagement {
id("com.gradle.plugin-publish") version "1.3.1"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("org.jetbrains.kotlin.jvm") version "2.2.0"
id("org.xbib.gradle.plugin.jflex") version "3.0.2"
id("org.unbroken-dome.xjc") version "2.0.0"
id("org.graalvm.buildtools.native") version "0.11.0"
}
}
Expand Down
Loading
Loading