我想要构建一个uberjar (又名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
}
}发布于 2012-06-12 04:05:21
我用以下代码替换了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
}
}排除是必要的,因为在它们不存在的情况下,您将遇到this问题。
发布于 2016-11-26 12:45:02
只需将其添加到java模块的build.gradle中即可。
mainClassName = "my.main.Class“
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}这将生成module_name/build/libs/module_name.jar文件。
发布于 2014-09-25 00:34:19
我发现这个project非常有用。使用它作为参考,我的Gradle 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'
}
}https://stackoverflow.com/questions/10986244
复制相似问题