【发布时间】:2019-07-19 10:45:20
【问题描述】:
TL;DR
我正在尝试以一个项目使用另一个项目构建的文件的方式配置两个 Gradle 项目。
第一个项目由includeBuild 添加到第二个项目中,该文件在第二个项目中定义为依赖项。
项目testA
settings.gradle:
rootProject.name = 'testA'
build.gradle:
group = 'org.test'
version = '0.0.0.1_test'
task someZip (type: Zip) {
from './settings.gradle'
archiveName = 'xxx.zip'
destinationDir = file("${buildDir}/test")
}
artifacts {
//TODO add something here?
}
项目testB
settings.gradle:
rootProject.name = 'testB'
if (System.getenv('LOCAL_COMPILATION') == 'true') {
includeBuild '../testA'
}
build.gradle:
if (System.getenv('LOCAL_COMPILATION') != 'true') {
repositories {
maven { url '192.168.1.100' }
}
}
configurations {
magic
}
dependencies {
magic 'org.test:xxx:0.0.0.+@zip'
}
task ultimateZip (type: Zip) {
from configurations.magic
archiveName = 'ultimate.zip'
destinationDir = file("${buildDir}/ultimate-test")
}
说明
您可能注意到该示例有一个使用 maven 存储库的选项。我想强调的是,最终会有可能做到这一点。
不过,使用 Maven 存储库不是这个问题的重点,除了解决方案不应该干涉之外。
(换句话说,你可以假设System.getenv('LOCAL_COMPILATION') == 'true'。)
问题是如何以其他项目能够识别的方式定义工件。
首选解决方案应该类似于 Java 插件所做的,因为我在我的项目中使用 jar 依赖项,它们通过 includeBuild 和存储库工作。
【问题讨论】:
标签: gradle artifact gradle-dependencies