我有一个使用gradle的小型Java项目,希望能够在生成常规jar和胖jar之间进行选择。
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
jar {
manifest {
attributes(
'Main-Class': 'com.myTest'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
implementation('org.apache.commons:commons-lang3:3.0')
testImplementation 'junit:junit:4.12'
}
如果我使用上面的脚本来构建,我会得到一个胖子。为了让我得到一个罐子,我将需要移除“罐子”块。我需要怎么做才能从命令行在两者之间切换?非常感谢!
为如下的fatJar任务创建新任务,
task fatJar(type: org.gradle.jvm.tasks.Jar, group: "build") {
manifest {
attributes(
'Main-Class': 'com.myTest'
)
}
baseName(project.name.concat("-fatJar"))
from {
configurations.runtimeClasspath.collect { it.directory ? it : zipTree(it)
}
}