我刚开始使用gradle (6.4.1),并启动了一个CLI可执行jar。
以前很管用的。
然后,我使用spring引导在CLI旁边添加了一个REST接口。Spring引导正常,但是CLI可执行jar被破坏了。它总是产生一个弹簧引导可执行文件。我需要保持这两种可执行的方法。
要解决这个问题,我已经为CLI可执行文件创建了一个单独的构建文件,但是jar是不可执行的,并且错误具有“无主清单属性”。
你能为我解决我的需要提供指导吗?
tldr;
为了成功地使用第二个构建文件进行构建,我从spring引导构建文件中获取了所有依赖项,但将spring引导插件切换到maven BOM方法,以避免产生只用于spring引导的可执行文件。
Spring引导生成文件
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
jar {
manifest {
attributes 'Main-Class': 'console.ConsoleExercices'
}
}
group = 'be.challenge'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
jcenter()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.4.0'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile group: 'org.apache.camel', name: 'camel-core', version: '3.4.0'
compile group: 'org.apache.camel', name: 'camel-servlet', version: '3.4.0'
compile group: 'org.apache.camel', name: 'camel-jackson', version: '3.4.0'
compile group: 'org.apache.camel', name: 'camel-swagger-java', version: '3.4.0'
testCompile group: 'org.apache.camel', name: 'camel-test', version: '3.4.0'
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
}
test {
useJUnit()
}可执行的CLI构建文件
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE' apply false
id 'war'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
jar {
manifest {
attributes 'Main-Class': 'be.console.ConsoleExercises'
}
archivesBaseName = 'console-exercises'
}
group = 'be.challenge'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
jcenter()
}
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.4.0'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile group: 'org.apache.camel', name: 'camel-core', version: '3.4.0'
compile group: 'org.apache.camel', name: 'camel-servlet', version: '3.4.0'
compile group: 'org.apache.camel', name: 'camel-jackson', version: '3.4.0'
compile group: 'org.apache.camel', name: 'camel-swagger-java', version: '3.4.0'
testCompile group: 'org.apache.camel', name: 'camel-test', version: '3.4.0'
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
}
test {
useJUnit()
}发布于 2020-07-22 21:10:29
发布于 2020-07-19 21:28:33
CLI项目应该使用application插件。它将确保它作为一个常规的JAR/CLI应用程序完全可以运行。
此外,使用implementation而不是compile。compile配置早就被废弃了,不应该再使用了。
https://stackoverflow.com/questions/62985467
复制相似问题