我有一个gradle多项目设置,我希望将其所有依赖项和输出JAR收集到顶层的ZIP中。我有一些工作,但是最终在ZIP文件中出现了重复项。我在official documentation on multi project setups中找不到任何有用的东西
结构
./multi-project
./multi-project/build.gradle
./multi-project/settings.gradle
./multi-project/bar
./multi-project/bar/build.gradle
./multi-project/foo
./multi-project/foo/build.gradle
顶级build.gradle
apply plugin: 'java'
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
}
task buildDist(type: Zip) {
from subprojects.configurations.compile into 'jars'
from subprojects.jar.outputs.files into 'jars'
}
Settings.gradle
include ':foo'
include ':bar'
foo和bar的较低级别的build.gradle文件(两者相同)
dependencies {
compile 'org.springframework:spring-beans:4.1.0.RELEASE'
}
当我从顶层运行gradle:buildDist时,ZIP有重复项
unzip -l build/distributions/multi-project.zip
Archive: build/distributions/multi-project.zip
Length Date Time Name
--------- ---------- ----- ----
0 2014-09-09 20:17 jars/
701334 2014-09-09 19:53 jars/spring-beans-4.1.0.RELEASE.jar
62050 2014-07-05 21:09 jars/commons-logging-1.1.3.jar
1005039 2014-09-09 19:53 jars/spring-core-4.1.0.RELEASE.jar
701334 2014-09-09 19:53 jars/spring-beans-4.1.0.RELEASE.jar
62050 2014-07-05 21:09 jars/commons-logging-1.1.3.jar
1005039 2014-09-09 19:53 jars/spring-core-4.1.0.RELEASE.jar
301 2014-09-09 20:12 jars/bar.jar
301 2014-09-09 20:12 jars/foo.jar
最佳答案
task buildDist(type: Zip) {
into 'jars'
from { subprojects.configurations.runtime }
from { subprojects.jar }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
要查看特定Gradle任务类型的所有配置选项,请查询Gradle Build Language Reference。
关于gradle - 分布ZIP中的多项目Gradle重复依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25752078/