我是一个新手摇篮。 我想建立一个uberjar(AKA fatjar),其中包括项目的所有传递依赖。 我需要什么线添加到我的“的build.gradle”?
这是我目前有:(我复制它从什么地方几天就回来,但不从那里回忆。)
task uberjar(type: Jar) {
from files(sourceSets.main.output.classesDir)
manifest {
attributes 'Implementation-Title': 'Foobar',
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Main-Class': mainClassName
}
}
您是否尝试过在该fatjar例如gradle这个食谱 ?
什么你要找的是影子插件的gradle产出
我更换了task uberjar(..
有以下几点:
jar {
from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
manifest {
attributes 'Implementation-Title': 'Foobar',
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Main-Class': mainClassName
}
}
需要的排除,因为在他们的缺席,你会打这个问题。
只需添加到您的Java模块的build.gradle。
mainClassName = “my.main.Class”
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
这将导致[MODULE_NAME] /编译/库/ [模块名] .jar文件。
我发现这个项目非常有用的。 使用它作为一个参考,我的摇篮uberjar任务是
task uberjar(type: Jar, dependsOn: [':compileJava', ':processResources']) {
from files(sourceSets.main.output.classesDir)
from configurations.runtime.asFileTree.files.collect { zipTree(it) }
manifest {
attributes 'Main-Class': 'SomeClass'
}
}