This message was deleted.
# community-support
s
This message was deleted.
a
try using testApi instead of testImplementation to add a dependency on the library - then it should be visible to the consuming project
m
Copy code
Could not find method testApi() for arguments
have "id java-library" in that build.gradle also. Is testApi from a version later than 6.0.1?
a
ah, does the plugin apply the ‘plain’ Java plugin? Try using the Java Library plugin instead
m
Thank you for responding, but still no joy:
Copy code
plugins {
        id 'java-library'
}
apply plugin: 'java-library'
The above is from the file with testApi failure.
a
hmm, I’m misremembering something then. I just tried it locally and yes, testApi is not available with Java Library.
m
I have attempted api, implementation, testImplementation and testRuntimeOnly against that library. Only testCompile works. Something must be different in how various classpaths are populated and/or shared.
a
the docs go into more detail about ‘implementation’ vs ‘api’ , and why they replace ‘compile’, but the short answer is that ‘compile’ is too leaky and overshares dependencies, even when they’re best not shared. ‘implementation’ is generally better because it’s more defensive, but sharing dependencies by defining them as ‘api’ can be useful sometimes (as you’re finding out!)
m
regular api vs implementation differences I understand. Its this corner case with a static initializer / test library that is giving me grief.
Looking for a way to "leak" what ever testCompileOnly used to leak.
a
it is possible because I have testApi in some projects, I’m just trying to figure out what plugin is defining it…
m
thank you.
a
I think it’s coming from the Kotlin JVM plugin, which you probably don’t want to add just to get testApi
instead it looks like the alternative is to use the test-fixtures plugin https://github.com/gradle/gradle/issues/8585#issuecomment-517152546
m
I was avoiding java-test-fixtures. Will try now.
a
I really recommend test fixtures, they’re a really neat way to share test utilities and keep the test sources clean. But in this case, you don’t need to dig into all of that. The plugin can be used just to provide the necessary Gradle config
m
This is a really old project. But times require we upgrade / update.
Will attempt your recommendation.
a
1. apply
java-test-fixtures
in the providing subproject 2. expose the library using
testFixturesApi(...)
3. in the consuming subproject, add a dependency using
testImplementation(testFixtures(project(":my-library")))
there’s no need to apply java-test-fixtures in the consuming subproject
m
... running ...
did not work. but that might just be me needing to play a bit. syntax was accepted.
a
possibly more dependencies need to be exposed
m
--info suggests still same problem. Not saying that means you are wrong. Just my source of clues.
again, this is not new code. worked before syntax changes for deprecation.
a
Gradle has a util for auto converting a Maven project to a Gradle project, and it will convert all dependencies to be ‘api’ dependencies, because even if it’s not best practice it’s closer to how Maven dependencies work, so it will at least convert the Maven config to a Gradle project that works. I mention this because it’s similar to migrating from ‘compile’ to ‘api’/‘implementation’
m
Adam. Thank you again. I have to step away for a little bit while there is still light outside. Will keep experimenting.
👍 1
a
my pleasure, enjoy the fresh air
v
Actually, you can find
testApi
in the Gradle userguide (while it indeed does not exist 😄)
Test source sets are not meant to be depended upon cross-project, so there usually is no
testApi
and also a reason why the
test-fixtures
were added I guess.
Btw.
```plugins {
id 'java-library'
}
apply plugin: 'java-library'```
is redundant. You first apply the plugin properly the new way and then again the legacy way. You should actually not have any
apply plugin:
anymore except for very special cases of plugins that break the
plugins { ... }
block when you are using Kotlin DSL.
m
@adam @Vampire Follow up: testFixtureApi did allow me to repair the dependency problem. Still took an extra day to isolate the areas impacted. Like I said, 156 subprojects.
Thanks to you both for responding.
👌 2