我现在提供的是我现在所拥有的 .
在下面的示例中,Jar任务生成一个Jar,其中包含Zip文件(来自另一个项目的工件) .
但是,我的最终目标是制作一个自我包含它的依赖性的超级 jar . 我来自Shadow插件,它似乎是一个干净的解决方案 .
我试图告诉我的ShadowJar任务包含Zip文件 - 但它不起作用 . 请参阅注释掉ShadowJar部分 .
所以,我现在拥有的是创建阴影 jar ,然后生成另一个包含阴影 jar 和拉链内容的jar . 我可以看到这条道路充满了陷阱(我不得不再次强制执行清单)....
理想情况下,我认为有一种方法可以在Shadow Jar中包含来自不同配置的工件,这是我在这里失败的Gradle知识限制 .
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.1.1'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.github.johnrengelman.shadow'
project.version = rootProject.ext.deployerVersion
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'maven central' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
}
configurations {
pkg
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile project(':Concenter.Foundation')
pkg project(path: ':Concenter.Platform', configuration: 'pkg')
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.11'
}
jar {
dependsOn ':Concenter.Platform:distZip'
manifest {
attributes(
'Main-Class': 'aqilco.concenter.deployer.Deployer',
)
}
from configurations.pkg
}
/*
shadowJar {
dependsOn ':Concenter.Platform:distZip'
manifest {
attributes(
'Main-Class': 'aqilco.concenter.deployer.Deployer',
)
}
from configurations.pkg
}
*/
task pkg(type: Jar) {
dependsOn ':Concenter.Platform:distZip'
dependsOn 'shadowJar'
archiveName = jar.baseName + "-" + jar.version + "-pkg." + jar.extension
from zipTree(shadowJar.archivePath)
from configurations.pkg
manifest {
attributes(
'Main-Class': 'aqilco.concenter.deployer.Deployer',
)
}
}