Skip to content

Commit cbd510f

Browse files
committed
fix(test-published-dependencies): declare JUnit launcher
Update the published dependency test builds to use Kotlin DSL task accessors and provider-backed configuration resolution. Add junit-platform-launcher alongside the JUnit BOM update because the missing launcher caused test execution problems at least on Gradle 9.5.
1 parent 076c5dc commit cbd510f

3 files changed

Lines changed: 53 additions & 18 deletions

File tree

test-published-dependencies/agent-logs-on-java-7/build.gradle.kts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import org.gradle.api.file.ConfigurableFileCollection
2+
import org.gradle.api.file.RegularFileProperty
3+
import org.gradle.api.tasks.Classpath
4+
import org.gradle.api.tasks.InputFile
5+
import org.gradle.api.tasks.PathSensitive
6+
import org.gradle.api.tasks.PathSensitivity
7+
import org.gradle.kotlin.dsl.application
8+
import org.gradle.kotlin.dsl.invoke
9+
import org.gradle.kotlin.dsl.java
10+
import org.gradle.process.CommandLineArgumentProvider
11+
112
plugins {
213
java
314
application
@@ -14,25 +25,46 @@ java {
1425
targetCompatibility = JavaVersion.VERSION_1_7
1526
}
1627

17-
val agent: Configuration by configurations.creating
28+
val agent = configurations.register("agent")
1829

1930
dependencies {
2031
agent("com.datadoghq:dd-java-agent:$version")
21-
testImplementation(platform("org.junit:junit-bom:5.9.2"))
32+
testImplementation(platform("org.junit:junit-bom:5.14.1"))
2233
testImplementation("org.junit.jupiter:junit-jupiter")
34+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
35+
}
36+
37+
abstract class AgentLogsOnJava7JvmArguments : CommandLineArgumentProvider {
38+
@get:Classpath
39+
abstract val agentClasspath: ConfigurableFileCollection
40+
41+
@get:InputFile
42+
@get:PathSensitive(PathSensitivity.RELATIVE)
43+
abstract val appJar: RegularFileProperty
44+
45+
override fun asArguments(): Iterable<String> = listOf(
46+
"-Dtest.published.dependencies.agent=${agentClasspath.singleFile}",
47+
"-Dtest.published.dependencies.jar=${appJar.get().asFile}",
48+
)
2349
}
2450

25-
tasks.named<Test>("test") {
26-
dependsOn("jar")
51+
val jarTask = tasks.jar
52+
53+
tasks.test {
54+
dependsOn(jarTask)
2755
useJUnitPlatform()
2856
testLogging {
2957
events("passed", "skipped", "failed")
3058
}
31-
jvmArgs("-Dtest.published.dependencies.agent=${agent.singleFile}")
32-
jvmArgs("-Dtest.published.dependencies.jar=${tasks.jar.get().archiveFile.get()}")
59+
jvmArgumentProviders.add(
60+
objects.newInstance(AgentLogsOnJava7JvmArguments::class.java).apply {
61+
agentClasspath.from(agent)
62+
appJar.set(jarTask.flatMap { it.archiveFile })
63+
}
64+
)
3365
}
3466

35-
tasks.named<Jar>("jar") {
67+
tasks.jar {
3668
manifest {
3769
attributes("Main-Class" to "test.published.dependencies.App")
3870
}
@@ -42,7 +74,7 @@ application {
4274
mainClass = "test.published.dependencies.App"
4375
}
4476

45-
tasks.named<JavaCompile>("compileTestJava") {
77+
tasks.compileTestJava {
4678
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
4779
targetCompatibility = JavaVersion.VERSION_1_8.toString()
4880
}

test-published-dependencies/ot-is-shaded/build.gradle.kts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
java
66
}
77

8-
val jarfile: Configuration by configurations.creating
8+
val jarfile = configurations.register("jarfile")
99

1010
dependencies {
1111
jarfile("com.datadoghq:dd-trace-ot:$version")
@@ -66,9 +66,9 @@ abstract class CheckJarContentsTask : DefaultTask() {
6666
}
6767
}
6868

69-
val jarFile = jarfile.filter { it.name.startsWith("dd-trace-ot") }.singleFile
69+
val jarFile = layout.file(jarfile.map { it.filter { file -> file.name.startsWith("dd-trace-ot") }.singleFile })
7070

71-
tasks.register<CheckJarContentsTask>("checkJarContents") {
71+
val checkJarContents = tasks.register<CheckJarContentsTask>("checkJarContents") {
7272
file.set(jarFile)
7373
expectedPatterns.set(
7474
listOf(
@@ -93,16 +93,18 @@ tasks.register<CheckJarContentsTask>("checkJarContents") {
9393
)
9494
}
9595

96-
tasks.register("checkJarSize") {
96+
val checkJarSize = tasks.register("checkJarSize") {
9797
inputs.file(jarFile)
9898
doLast {
99+
val jar = jarFile.get().asFile
99100
// Arbitrary limit to prevent unintentional increases to the dd-trace-ot jar size
100101
// Raise or lower as required
101-
assert(jarFile.length() <= 8 * 1024 * 1024)
102+
if (jar.length() > 8 * 1024 * 1024) {
103+
throw GradleException("jar size is too big: ${jar.length()} bytes")
104+
}
102105
}
103106
}
104107

105-
tasks.named("check") {
106-
dependsOn("checkJarContents")
107-
dependsOn("checkJarSize")
108+
tasks.check {
109+
dependsOn(checkJarContents, checkJarSize)
108110
}

test-published-dependencies/ot-pulls-in-api/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ java {
99

1010
dependencies {
1111
implementation("com.datadoghq:dd-trace-ot:$version")
12-
testImplementation(platform("org.junit:junit-bom:5.9.2"))
12+
testImplementation(platform("org.junit:junit-bom:5.14.1"))
1313
testImplementation("org.junit.jupiter:junit-jupiter")
14+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
1415
}
1516

16-
tasks.named<Test>("test") {
17+
tasks.test {
1718
useJUnitPlatform()
1819
testLogging {
1920
events("passed", "skipped", "failed")

0 commit comments

Comments
 (0)