我想基于项目settings.gradle中定义的自定义设置构建我的Java库的一些功能。
示例:
的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
答案 0 :(得分:2)
首先,将您的参数移至gradle.properties
其次,使用简单的if
来控制源集:
sourceSets (
if ("true" == "$extraFeatures") {
}
)
示例(我没有测试过):
sourceSets {
main {
java {
srcDir 'src/java'
if ("true" == "$extraFeatures") {
srcDir 'src/java/mysecretcode'
}
}
}
}