[英]How can I create single executable jar in my gradle project
I am using gradle 6.2 version with jdk 8 in my application, it's builing 2 jar files under build/libs/ directory.我在我的应用程序中使用 gradle 6.2 版本和 jdk 8,它在 build/libs/ 目录下构建了 2 个 jar 文件。 How can I create the single executable jar in my application?如何在我的应用程序中创建单个可执行文件 jar?
My build.gradle,我的build.gradle,
plugins {
id 'com.google.cloud.tools.jib' version '2.2.0'
id 'application'
id 'java'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
jib.to.image = 'gcr.io/' + project.property('gcpProjectId') + '/my-application'
jib.container.creationTime = 'USE_CURRENT_TIMESTAMP'
mainClassName = "com.foo.Myapplication"
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Created Jar files:创建了 Jar 个文件:
ls -ltr build/libs/
total 31184
-rw-r--r-- 1 user 15986229 Jun 9 20:22 my-application-1.0.0.jar
-rw-r--r-- 1 user 15942345 Jun 9 20:22 my-application-1.0.0-all.jar
Why it's creating -all.jar while executing "gradle clean build"?为什么它在执行“gradle clean build”时创建 -all.jar? What did am wrong here?这里出了什么问题? Kindly provide your thoughts on this.请提供您对此的想法。
Gradle Shadow Plugin seems to be exactly what you need. Gradle Shadow Plugin似乎正是您所需要的。 It has interop with Gradle's application
plugin as well .它也可以与 Gradle 的application
插件互操作。
I am able to build a single jar, after modifying the build.gradle likes the following,我能够构建单个 jar,在修改 build.gradle 后,如下所示,
build.gradle, build.gradle,
plugins {
id 'com.google.cloud.tools.jib' version '2.2.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
jib.to.image = 'gcr.io/' + project.property('gcpProjectId') + '/my-application'
jib.container.creationTime = 'USE_CURRENT_TIMESTAMP'
jar {
manifest {
attributes 'Main-Class': 'com.foo.Myapplication'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.