mirror of https://github.com/apache/kafka.git
KAFKA-18356: Explicitly set up instrumentation for inline mocking (Java 21+) (#18339)
Reviewers: Mickael Maison <mickael.maison@gmail.com>, Ismael Juma <ismael@juma.me.uk>
This commit is contained in:
parent
9e9d2a23ef
commit
527467d053
35
build.gradle
35
build.gradle
|
@ -484,11 +484,36 @@ subprojects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Workaround for Mockito Java Agent restrictions in Java 21+
|
||||||
|
// Starting with Java 21, the JDK restricts libraries from attaching a Java agent
|
||||||
|
// to their own JVM. As a result, Mockito’s inline mock maker (mockito-core)
|
||||||
|
// fails without explicit instrumentation, and the JVM consistently emits warnings.
|
||||||
|
// See also: https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#mockito-instrumentation
|
||||||
|
afterEvaluate { subproject ->
|
||||||
|
def hasMockitoCore = subproject.configurations.findAll {
|
||||||
|
it.canBeResolved
|
||||||
|
}.any { config ->
|
||||||
|
config.incoming.dependencies.any { dependency ->
|
||||||
|
"$dependency" == libs.mockitoCore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasMockitoCore) {
|
||||||
|
subproject.configurations {
|
||||||
|
mockitoAgent {
|
||||||
|
transitive = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subproject.dependencies {
|
||||||
|
mockitoAgent libs.mockitoCore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The suites are for running sets of tests in IDEs.
|
// The suites are for running sets of tests in IDEs.
|
||||||
// Gradle will run each test class, so we exclude the suites to avoid redundantly running the tests twice.
|
// Gradle will run each test class, so we exclude the suites to avoid redundantly running the tests twice.
|
||||||
def testsToExclude = ['**/*Suite.class']
|
def testsToExclude = ['**/*Suite.class']
|
||||||
|
|
||||||
|
|
||||||
// This task will copy JUnit XML files out of the sub-project's build directory and into
|
// This task will copy JUnit XML files out of the sub-project's build directory and into
|
||||||
// a top-level build/junit-xml directory. This is necessary to avoid reporting on tests which
|
// a top-level build/junit-xml directory. This is necessary to avoid reporting on tests which
|
||||||
// were not run, but instead were restored via FROM-CACHE. See KAFKA-17479 for more details.
|
// were not run, but instead were restored via FROM-CACHE. See KAFKA-17479 for more details.
|
||||||
|
@ -518,6 +543,14 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
def mockitoAgentConfig = configurations.findByName('mockitoAgent')
|
||||||
|
if (mockitoAgentConfig) {
|
||||||
|
jvmArgs("-javaagent:${mockitoAgentConfig.asPath}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
maxParallelForks = maxTestForks
|
maxParallelForks = maxTestForks
|
||||||
ignoreFailures = userIgnoreFailures
|
ignoreFailures = userIgnoreFailures
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue