我试图制作一个具有依赖项的 jar,因为NoClassDefFoundError在使用 启动 jar 时我得到了java -Dspring.config.location=myProperties -jar myJar,经过大量搜索后,我发现我可以在 jar 块中使用以下解决方案来实现此目的:
from{
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
}
Run Code Online (Sandbox Code Playgroud)
除了构建 jar 时的时间(大约 1 分钟)之外,这一切都很好,并且根据这个答案:Gradle: Build 'fat jar' with Spring Boot Dependency我不需要创建额外的任务,是足够了,bootRepackage但我收到了上面提到的错误bootRepackage,我不明白为什么。
这是我的内容build.gradle,我正在使用 spring boot 1.5.15:
/*
* This file was generated by the Gradle 'init' task.
*/
buildscript {
ext.springBootVersion = '1.5.15.RELEASE'
ext.managementVersion = '1.0.6.RELEASE'
ext.axis2Version = '1.7.9'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
//classpath "io.spring.gradle:dependency-management-plugin:${managementVersion}" …Run Code Online (Sandbox Code Playgroud)