简体   繁体   中英

Maven build and deploy for different platform targets (like Android and Java SE)

I have a utility library which is used in "normal" Java projects and in Android projects.

There is a subtle difference between those platforms:

  • Java SE needs org.json:json:20080701 as a dependency
  • Android already provides a compile-compatible library for JSON in the core platform

What I'd like to have

Best case would be to have a single pom.xml which creates and deploys 2 artifacts, eg

  • mylib-android-1.2.0.jar
  • mylib-1.2.0.jar

I've found something like "classifier", which might be used for this aim, but I only saw this in the context of dependencies, not for defining build artifacts.

Could somebody point me to an example (maybe a famous open source project) how to do this?

Remark: I've tried defining org.json:json:20080701 with <scope>provided</scope> , but Android Gradle build is complaining about potential incompatibilities and this would force "Java SE" users to add this dependency. Not the desired solution.

In case you want to see the pom.xml, here it is: https://github.com/hgoebl/DavidWebb/blob/v1.1.0/pom.xml

And this is the Gradle output when using the library as it is currently:

WARNING: Dependency org.json:json:20080701 is ignored for releaseUnitTest as it may be conflicting with the internal version provided by Android. In case of problem, please repackage with jarjar to change the class packages

What you're looking for is Maven Profiles . You can customize dependencies for each profile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM