11import io.opentelemetry.javaagent.muzzle.generation.ClasspathByteBuddyPlugin
22import io.opentelemetry.javaagent.muzzle.generation.ClasspathTransformation
3- import io.opentelemetry.javaagent.muzzle.generation.ConfigurationCacheFriendlyByteBuddyTask
3+ import net.bytebuddy.ClassFileVersion
4+ import net.bytebuddy.build.gradle.ByteBuddySimpleTask
45import net.bytebuddy.build.gradle.Transformation
56
67plugins {
@@ -49,7 +50,7 @@ val languageTasks = LANGUAGES.map { language ->
4950 return @map null
5051 }
5152 val compileTask = tasks.named(compileTaskName)
52- createLanguageTask(compileTask, language)
53+ createLanguageTask(compileTask, " byteBuddy ${ language.replaceFirstChar( Char ::titlecase)} " )
5354}.filterNotNull()
5455
5556tasks {
@@ -59,43 +60,29 @@ tasks {
5960}
6061
6162fun createLanguageTask (
62- compileTaskProvider : TaskProvider <* >, language : String ): TaskProvider <* > {
63- val taskName = " byteBuddy${language.replaceFirstChar { it.uppercase() }} "
64- val mainSourceSet = sourceSets.main.get()
65-
66- // Create the input classpath from the existing logic in the main part
67- val inputClasspath = (mainSourceSet.output.resourcesDir?.let { codegen.plus(project.files(it)) }
68- ? : codegen)
69- .plus(mainSourceSet.output.dirs) // needed to support embedding shadowed modules into instrumentation
70- .plus(configurations.runtimeClasspath.get())
71-
72- val byteBuddyTask = tasks.register(taskName, ConfigurationCacheFriendlyByteBuddyTask ::class .java) {
73- dependsOn(compileTaskProvider, mainSourceSet.processResourcesTaskName)
74-
75- transformations.add(createTransformation(inputClasspath, pluginName))
76-
77- // Configure the ByteBuddy task properties directly during task creation
63+ compileTaskProvider : TaskProvider <* >, name : String ): TaskProvider <* > {
64+ return tasks.register<ByteBuddySimpleTask >(name) {
65+ setGroup(" Byte Buddy" )
66+ outputs.cacheIf { true }
67+ classFileVersion = ClassFileVersion .JAVA_V8
68+ var transformationClassPath = inputClasspath
7869 val compileTask = compileTaskProvider.get()
7970 // this does not work for kotlin as compile task does not extend AbstractCompile
8071 if (compileTask is AbstractCompile ) {
8172 val classesDirectory = compileTask.destinationDirectory.asFile.get()
82- val rawClassesDirectory = File (classesDirectory.parent, " ${classesDirectory.name} raw" ).absoluteFile
83-
84- // Configure the compile task to write to rawClassesDirectory
73+ val rawClassesDirectory: File = File (classesDirectory.parent, " ${classesDirectory.name} raw" )
74+ .absoluteFile
75+ dependsOn(compileTask)
8576 compileTask.destinationDirectory.set(rawClassesDirectory)
86-
87- // Configure ByteBuddy task properties
8877 source = rawClassesDirectory
8978 target = classesDirectory
9079 classPath = compileTask.classpath.plus(rawClassesDirectory)
91-
92- // Clear and set transformations with correct classpath
93- transformations.clear()
94- transformations.add(createTransformation(inputClasspath.plus(files(rawClassesDirectory)), pluginName))
80+ transformationClassPath = transformationClassPath.plus(files(rawClassesDirectory))
81+ dependsOn(compileTask, sourceSet.processResourcesTaskName)
9582 }
96- }
9783
98- return byteBuddyTask
84+ transformations.add(createTransformation(transformationClassPath, pluginName))
85+ }
9986}
10087
10188fun createTransformation (classPath : FileCollection , pluginClassName : String ): Transformation {
0 commit comments