I would like to have some features of my Java library conditionaly built based on custom settings defined in project's settings.gradle.
Example:
build.gradle
apply plugin: 'java'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
sourceSets {
extra_feature
}
dependencies {
compile 'net.java.dev.jna:jna:4.1.0'
}
// I need a way to link the "extra_feature" sourceSets to the default "build" action based on some settings in settings.gradle.
settings.gradle
extraFeatures = true
First, move your parameter to gradle.properties
Second, use simple if
to control source sets:
sourceSets (
if ("true" == "$extraFeatures") {
}
)
Example (I didnt test it):
sourceSets {
main {
java {
srcDir 'src/java'
if ("true" == "$extraFeatures") {
srcDir 'src/java/mysecretcode'
}
}
}
}