[英]Gradle product flavor in “pure” gradle (not android gradle)
我想用gradle为不同的客户构建一个java库。 在“纯粹”的gradle中有没有类似于android知道的产品风味?
谢谢。
答案是肯定的,但你必须使用新的Gradle软件模型,这种模式非常热烈。 这将是一条充满痛苦的道路,因为你将成为一个开拓者,因为我已经学会了将它用于C / Cpp项目。 以下是您的构建的外观。
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)
}
}
参考文献:1)Java软件模型https://docs.gradle.org/current/userguide/java_software.html 2)Flavors https://docs.gradle.org/current/userguide/native_software.html注意:我不是确定Java软件模型支持的口味有多好,我会做一些测试和报告。
更新:它是可行的,但目前JvmLibrarySpec不支持。 我将尝试使用如何执行自定义规范的示例发布更完整的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.