Build Flavors Project for Java
Build Flavors are commonly used in android apps via android gradle plugin. This allows the project to have a directory structure
src
- main
- com.stack.A.java
- debug
- com.stack.B.java
- release
- com.stack.B.java
This will only compile the correct one B.java
depending on the release type selected.
Is there a way to mirror this functionality without using the android gradle plugin and only using the java plugin?
source to share
It's called sourceSet in Java plugin, see https://docs.gradle.org/current/userguide/java_plugin.html
main
and test
source sets are created automatically, to add more source sets, you can do something like below. Basically both release and debug also use codes mostly
apply plugin: 'java'
sourceSets {
release {
java {
srcDirs 'src/main/java', 'src/release/java'
}
}
debug {
java {
srcDirs 'src/main/java', 'src/debug/java'
}
}
}
source to share
I wrote a plugin for this. For example,
apply plugin: 'com.lazan.javaflavours'
javaFlavours {
flavours = ['free', 'paid']
}
Then sources from src/free/java
and src/paid/java
and resources to src/free/resources
andsrc/paid/resources
Github project: https://github.com/uklance/gradle-java-flavours
source to share