我有一个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
答案 0 :(得分:10)
task buildDist(type: Zip) {
into 'jars'
from { subprojects.configurations.runtime }
from { subprojects.jar }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
要查看特定Gradle任务类型的所有配置选项,请参阅Gradle Build Language Reference。
答案 1 :(得分:0)
我最好提出
实施例
task buildDist(type: Zip) {
gradle.taskGraph.whenReady { taskGraph ->
def uniqueFiles = new HashSet()
uniqueFiles.addAll(subprojects.configurations.compile.resolvedConfiguration.resolvedArtifacts.file)
uniqueFiles.addAll(subprojects.jar.outputs.files)
from uniqueFiles into 'jars'
}
}