Skip to content

Commit a697735

Browse files
committed
Gradle cache config: bytebuddy (alt)
1 parent 47cdd86 commit a697735

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import io.opentelemetry.javaagent.muzzle.generation.ClasspathByteBuddyPlugin
22
import io.opentelemetry.javaagent.muzzle.generation.ClasspathTransformation
3-
import net.bytebuddy.ClassFileVersion
4-
import net.bytebuddy.build.gradle.ByteBuddySimpleTask
3+
import io.opentelemetry.javaagent.muzzle.generation.ConfigurationCacheFriendlyByteBuddyTask
54
import net.bytebuddy.build.gradle.Transformation
65

76
plugins {
@@ -61,10 +60,9 @@ tasks {
6160

6261
fun createLanguageTask(
6362
compileTaskProvider: TaskProvider<*>, name: String): TaskProvider<*> {
64-
return tasks.register<ByteBuddySimpleTask>(name) {
63+
return tasks.register(name, ConfigurationCacheFriendlyByteBuddyTask::class.java) {
6564
setGroup("Byte Buddy")
6665
outputs.cacheIf { true }
67-
classFileVersion = ClassFileVersion.JAVA_V8
6866
var transformationClassPath = inputClasspath
6967
val compileTask = compileTaskProvider.get()
7068
// this does not work for kotlin as compile task does not extend AbstractCompile
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.opentelemetry.javaagent.muzzle.generation
2+
3+
import net.bytebuddy.build.Plugin
4+
import net.bytebuddy.build.gradle.ByteBuddySimpleTask
5+
import org.gradle.api.tasks.TaskAction
6+
import java.io.IOException
7+
8+
/**
9+
* Byte Buddy task variant that avoids calling getProject() during task execution,
10+
* making it compatible with Gradle configuration cache. Can be removed once
11+
* https://github.com/raphw/byte-buddy/pull/1874 is released.
12+
*/
13+
open class ConfigurationCacheFriendlyByteBuddyTask : ByteBuddySimpleTask() {
14+
15+
@TaskAction
16+
@Throws(IOException::class)
17+
override fun apply() {
18+
val sourceDir = source
19+
val targetDir = target
20+
21+
if (sourceDir != targetDir && deleteRecursively(targetDir)) {
22+
logger.debug("Deleted all target files in {}", targetDir)
23+
}
24+
25+
doApply(
26+
Plugin.Engine.Source.ForFolder(sourceDir),
27+
Plugin.Engine.Target.ForFolder(targetDir)
28+
)
29+
}
30+
}

0 commit comments

Comments
 (0)