我希望根据项目的 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.
设置.gradle
extraFeatures = true
最佳答案
首先,将参数移至 gradle.properties
其次,使用简单的if
来控制源集:
sourceSets (
if ("true" == "$extraFeatures") {
}
)
示例(我没有测试):
sourceSets {
main {
java {
srcDir 'src/java'
if ("true" == "$extraFeatures") {
srcDir 'src/java/mysecretcode'
}
}
}
}
关于java - 基于 gradle.settings 的 Gradle sourceSets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32433142/