我有一个Java项目,它具有几个依赖项,例如:
dependencies {
compile("com.whatever.jar:jar-1:1.2.3")
compile("com.whatever.jar:jar-2:4.5.6")
compile("com.whatever.jar:jar-3:7.8.9")
}
我将其打包为jar库,并将其与描述那些依赖项的POM文件一起发布到存储库中:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.project</groupId>
<artifactId>my-library</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.whatever.jar</groupId>
<artifactId>jar-1</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.whatever.jar</groupId>
<artifactId>jar-2</artifactId>
<version>4.5.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.whatever.jar</groupId>
<artifactId>jar-3</artifactId>
<version>7.8.9</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
我也有another项目,该项目取决于以前在编译时构建的jar:
dependencies {
compileOnly("com.my.project:my-library:1.0.0")
}
我想创建一个构建第二个项目并创建一个包含com.my.project:my-library:1.0.0
jar及其传递依赖项(jar-1
,jar-2
和jar-3
)的zip文件的任务。
task createZip << {
into('lib') {
// here I would like to do something like (it's a horrible pseudo-code):
from configurations.(com.my.project:my-library:1.0.0).jar.transitiveDependencies.files
}
}
我该如何实现?
task uberJar(type: Jar) {
dependsOn classes
from sourceSets.main.runtimeClasspath.collect { it.directory?fileTree(it):zipTree(it)}
classifier = 'uber-jar'
}
assemble.dependsOn uberJar