Getting pure-java modules with ThreeTenBP to play nice with ThreeTenABP?
See original GitHub issueDisclaimer: this is probably a gradle config issue rather than an issue with this library per-se. But hopefully this issue is relevant to android developers wanting to use JSR 310 in multi-module projects.
I have a pure java (non-android) gradle module called common
with some utility functions for building ZonedDateTime objects. It depends on the standard jvm backport library (org.threeten:threetenbp
).
What I’d like is to have the android app module depend on the common
module to make use of these platform-independent utility functions, but depend on threetenABP instead for performance. Should this be possible? Attempting to do it naiively gives this build error:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDevelopDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/threeten/bp/format/ChronologyText.properties
File1: /Users/matthewcl/.gradle/caches/modules-2/files-2.1/org.threeten/threetenbp/1.3.1/5769e9c27cd5ba74cd3a73785dde0bbb5a2d3c0d/threetenbp-1.3.1.jar
File2: /Users/matthewcl/.gradle/caches/modules-2/files-2.1/org.threeten/threetenbp/1.3.1/fecd59cfa6acebf3d0f2f41f55a1cc3e24e59726/threetenbp-1.3.1-no-tzdb.jar
From what I understand, the same public classes and interfaces are in use in both modules (e.g. ZonedDateTime). It seems like something like gradle’s provided
keyword to have compilation succeed and yet use ABP at runtime would work, but I haven’t had much success with it.
Any thoughts?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:8 (3 by maintainers)
I got it working like this:
apk
): use ThreeTen Backport for Android (including timezone-info):implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'
compileOnly 'org.threeten:threetenbp:1.3.6:no-tzdb'
testImplementation 'org.threeten:threetenbp:1.3.6'
I think, the substitution that @JakeWharton mentions in this comment should only be required when you use an external library which uses
'org.threeten:threetenbp'
to avoid the slow loading of the time-zone info.@tmtron Correct me if I’m wrong, but the reason your solution works is the
compileOnly
declaration.compileOnly
dependencies are not included on the runtime class-path and are non-transitive (meaning they will not be included in dependent projects). However, in most cases, wouldn’t you need the ThreeTen library to be accessible at runtime by the Java-only modulecommon
? Also, is there any particular reason you’re using theno-tzdb
version of ThreeTen Backport?Anyways, in my case, I needed the time-zone version of ThreeTenBackport in my Java-only module and I also couldn’t make it a
compileOnly
dependency, so I just excluded it in my Android moduleapp
where I define thecommon
module as a dependency.In my Java-only
common
modulebuild.gradle
:In my Android
app
modulebuild.gradle
:(sidenote: I’m using the new
implementation
syntax instead ofcompile
)Just another solution in case it helps anyone!