This message was deleted.
# community-support
s
This message was deleted.
v
Is there a way to disable inheritance for the
testImplementation
configuration? I.e., it doesn't inherit the
implementation
dependencies.
Copy code
configurations.implementation {
    setExtendsFrom(listOf())
}
Also, are there other test configurations that inherit from main configuration?
testRuntimeOnly
https://github.com/gradle/gradle/blob/master/platforms/jvm/plugins-java/src/main/java/org/gradle/api/plugins/JavaPlugin.java#L381-L382
a
You might be looking for the JVM Test Suite https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html, so you can define a custom test source with independent dependencies
m
I've not used JVM Test Suite, but that might be what I'm looking for. I want my unit tests to behave as if they're running from a separate module. The context is that when my unit tests compiles, I want to catch an
-Xlint:classfile
compilation warning(/error with
-Werror
) that would happen if I incorrectly made a dependency an
implementation
dependency instead of an
api
dependency. You won't see that warning/error when you run the unit tests, but you will see it when you try to use the types in that module from another module.
OK, let me now ask a more focused question about `jvm-test-suite`: is there a way to get the default test suite to behave like the other test suites w.r.t. dependencies? If I created, e.g., a
realUnitTests
test suite--and did a bulk-move of test sources from
src/test/java
to
src/realUnitTests/java
--I could get the behavior I want: each test suite starts from a blank slate in terms of dependencies. But is there a way to get that same blank slate behavior in the default test suite (which means that a bulk-move is not needed)?
Btw, this did not work:
Copy code
configurations.testImplementation {
    setExtendsFrom(listOf())
}
It had an unfortunate side-effect: when I ran the tests, I got `ClassNotFoundException`(?) (I think it was that one, may have been something similar) exceptions; the
implementation
dependencies for the
main
sources were not available at runtime.
a
I will wager that bulk moving will be much easier than trying to hack around with excluding dependencies in Gradle 😅
v
I agree with Adam, that if you don't like the default behavior, easiest is to just use a different test suite. Otherwise you also need to check on Gradle updates whether something more is configured on the default test suite and need to adapt it. But currently what the
java
plugin does is setting • the compile classpath of the default test suite's source set to ◦ the output of the main source set ◦ and the default test suite's source set's compile classpath configuration • the runtime classpath of the default test suites's source set to ◦ the output of the default test suites's source set, ◦ the output of the main source set ◦ and the default test suite's source set's runtime classpath configuration • the default test suite's implementation configuration to extend from the main source set's implementation configuration • the default test suite's runtimeOnly configuration to extend from the main source set's runtimeOnly configuration If you want the behavior of custom test suites, you would need to revert those changes to their default settings, which I cannot tell you from the top of my head.
You could also declare the custom test suite, just configure its source set to use the sources and resource from
src/test/...
make
test
task depend on the custom test task, and disable the
test
task. Then when the
test
task is run, it first runs the custom test task, itself does nothing as it is disabled, and the custom test task uses the unmoved sources from
src/test/...
. You might also want to disable other tasks like
processTestResources
,
compileTestJava
, and so on to avoid doing unnecessary work. But with that setup it should work without moving the actual files. It is just a bit awkward setup. 🙂