I want to build a java library for different customers with gradle. Is there something like product flavors known from android in "pure" gradle?
Thanks.
The answer is yes but you will have to use the new Gradle software model which is very much incubating. It will be a road full of pain as you will be a trail blazer as I have learned using it for a C/Cpp project. Here is generally how your build will look like.
plugins {
id 'jvm-component'
id 'java-lang'
}
model {
buildTypes {
debug
release
}
flavors {
free
paid
}
components {
server(JvmLibrarySpec) {
sources {
java {
if (flavor == flavors.paid) {
// do something to your sources
}
if (builtType == buildTypes.debug) {
// do something for debuging
}
dependencies {
library 'core'
}
}
}
}
core(JvmLibrarySpec) {
dependencies {
library 'commons'
}
}
commons(JvmLibrarySpec) {
api {
dependencies {
library 'collections'
}
}
}
collections(JvmLibrarySpec)
}
}
References: 1) Java Software Model https://docs.gradle.org/current/userguide/java_software.html 2) Flavors https://docs.gradle.org/current/userguide/native_software.html note: I'm not sure how well flavors are supported the Java Software Model, I will do some testing and report back.
Update: It is doable but is not currently supported by the JvmLibrarySpec. I will try to post a more complete answer with an example of how to do the custom spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With