Skip to content

Commit 37d74f7

Browse files
committed
instrumentation-api-incubator: make jflex task configuration-cache friendly
1 parent 12874fb commit 37d74f7

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

instrumentation-api-incubator/build.gradle.kts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
plugins {
2-
id("org.xbib.gradle.plugin.jflex")
3-
42
id("otel.java-conventions")
53
id("otel.animalsniffer-conventions")
64
id("otel.jacoco-conventions")
@@ -10,7 +8,11 @@ plugins {
108

119
group = "io.opentelemetry.instrumentation"
1210

11+
val jflex = configurations.create("jflex")
12+
1313
dependencies {
14+
jflex("de.jflex:jflex:1.9.1")
15+
1416
api("io.opentelemetry.semconv:opentelemetry-semconv")
1517
api(project(":instrumentation-api"))
1618
api("io.opentelemetry:opentelemetry-api-incubator")
@@ -24,6 +26,41 @@ dependencies {
2426
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
2527
}
2628

29+
val jflexSourceDir = layout.projectDirectory.dir("src/main/jflex")
30+
val jflexOutputDir = layout.buildDirectory.dir("generated/sources/jflex")
31+
32+
val generateJflex by tasks.registering(JavaExec::class) {
33+
classpath(jflex)
34+
mainClass.set("jflex.Main")
35+
36+
inputs.dir(jflexSourceDir)
37+
outputs.dir(jflexOutputDir)
38+
39+
val sourceDir = jflexSourceDir
40+
val outputDirProvider = jflexOutputDir
41+
42+
doFirst {
43+
val outputDir = outputDirProvider.get().asFile
44+
outputDir.mkdirs()
45+
val specFile = sourceDir.asFile.resolve("SqlSanitizer.jflex")
46+
args(
47+
"-d", outputDir.absolutePath,
48+
"--nobak",
49+
specFile.absolutePath,
50+
)
51+
}
52+
}
53+
54+
sourceSets {
55+
main {
56+
java.srcDir(jflexOutputDir)
57+
}
58+
}
59+
60+
tasks.compileJava {
61+
dependsOn(generateJflex)
62+
}
63+
2764
tasks {
2865
// exclude auto-generated code
2966
named<Checkstyle>("checkstyleMain") {
@@ -38,7 +75,11 @@ tasks {
3875
}
3976

4077
sourcesJar {
41-
dependsOn("generateJflex")
78+
dependsOn(generateJflex)
79+
// Avoid configuration cache issue by not capturing task reference
80+
from("src/main/jflex") {
81+
include("**/*.java")
82+
}
4283
}
4384

4485
val testStableSemconv by registering(Test::class) {

0 commit comments

Comments
 (0)