Skip to content

Commit 5b1ee90

Browse files
committed
fix the Gradle configuration cache issue by lazily configuring Mockito and lazily resolving the testRuntimeClasspath mockito-core dependency
1 parent 754edea commit 5b1ee90

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

operator/build.gradle.kts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,29 @@ tasks.quarkusAppPartsBuild {
7171
doNotTrackState("Always execute Gradle task quarkusAppPartsBuild to generate the K8s deploy manifest kubernetes.yml, the CRDs, and to publish the Helm chart")
7272
}
7373

74-
tasks.withType<Test> {
74+
val mockitoAgentProvider = configurations.named("testRuntimeClasspath").map { classpath ->
75+
classpath.find { it.name.contains("mockito-core") }
76+
}
77+
78+
tasks.withType<Test>().configureEach {
7579
// Required for the HelmTest
7680
dependsOn(tasks.quarkusAppPartsBuild)
7781

78-
val mockitoAgent = configurations.testRuntimeClasspath.get().find {
79-
it.name.contains("mockito-core")
80-
}
81-
if (mockitoAgent != null) {
82-
jvmArgs("-javaagent:${mockitoAgent.absolutePath}")
82+
jvmArgumentProviders.add(MockitoArgumentProvider(mockitoAgentProvider))
83+
}
84+
85+
class MockitoArgumentProvider(
86+
@get:Optional
87+
@get:InputFile
88+
@get:PathSensitive(PathSensitivity.NONE)
89+
val agentProvider: Provider<File>
90+
) : CommandLineArgumentProvider {
91+
override fun asArguments(): Iterable<String> {
92+
val agentFile = agentProvider.orNull
93+
return if (agentFile != null) {
94+
listOf("-javaagent:${agentFile.absolutePath}")
95+
} else {
96+
emptyList()
97+
}
8398
}
8499
}

0 commit comments

Comments
 (0)