Issue with unit tests in multi-module project
erawhctim opened this issue · 4 comments
I was seeing the unit testing issues described in #14, and successfully applied the solutions outlined - however when I try to declare the threetenabp dependencies in another module via gradle's api
and testApi
commands, I'm still seeing the ZoneRulesException: No time-zone data files registered
error.
It's pretty clear that the change to api
is the problem, but I'm just curious if someone knows why and/or how I can possibly change my gradle setup to get it to work? It's ideal to declare dependencies like this that are re-used throughout multiple modules in the base "core" module and let them transitively apply, instead of having to redeclare in every module's gradle file. Any help is appreciated :)
I have a core
module and a main app
module that depends on it, relevant info from gradle files below:
Declaring in app
build.gradle (working):
implementation project(':core')
implementation 'com.jakewharton.threetenabp:threetenabp:1.0.4'
testImplementation 'org.threeten:threetenbp:1.3.2'
Declaring in core
build.gradle (not working):
api 'com.jakewharton.threetenabp:threetenabp:1.0.4'
testApi 'org.threeten:threetenbp:1.3.2'
+1 I reproduce this exact issue with the multi-modules project I'm working on and the usage of testApi
. If I move my test dependency to the specific module in which I need it instead of my core
shared module with testImplementation
, then my unit test works.
I'm not very experienced in how gradle works in terms of icluding build dependencies, but from my understanding gradle won't include dependencies of your test dependencies in the resulting artifact. What it means is that test dependencies are not transitive, so you must include testImplementation
in each module where you need it.
since this has been open for a while, for anyone else who lands here, in a similar setup i ran into the same issue. adding the second line suggested above (testApi...
) worked for me:
// in another module's build.gradle.kts
// ...
api("com.jakewharton.threetenabp:threetenabp:_")
testApi("org.threeten:threetenbp:_")
note that i have in versions.properties
:
...
version.com.jakewharton.threetenabp..threetenabp=1.2.4
version.org.threeten..threetenbp=1.4.5
...
since this has been open for a while, for anyone else who lands here, in a similar setup i ran into the same issue. adding the second line suggested above (
testApi...
) worked for me:// in another module's build.gradle.kts // ... api("com.jakewharton.threetenabp:threetenabp:_") testApi("org.threeten:threetenbp:_")
note that i have in
versions.properties
:... version.com.jakewharton.threetenabp..threetenabp=1.2.4 version.org.threeten..threetenbp=1.4.5 ...
But don't forget that these versions use different TZDB versions, as ThreeTenBP 1.4.5 uses 2020b, while ThreeThenABP 1.2.4 uses 2020a.