【发布时间】:2020-11-09 02:51:30
【问题描述】:
我是 gradle (6.4.1) 的新手并启动了一个 CLI 可执行 jar。
它曾经工作过。
然后我使用 spring boot 在 CLI 旁边添加了一个 REST 接口。 Spring boot 正在运行,但 CLI 可执行 jar 已损坏。它总是产生一个弹簧启动可执行文件。我需要保留这两种可执行的方法。
为了解决这个问题,我创建了一个专用于 CLI 可执行文件的单独构建文件,但 jar 不是可执行文件,并且出现 “no main manifest attribute” 错误。
您能否为我提供指导以解决我的需求。
tldr;
为了使用第二个构建文件成功构建,我从 spring boot 构建文件中获取了所有依赖项,但将 spring boot 插件切换为 maven BOM 方法以避免生成 spring boot 唯一可执行文件。
Spring Boot 构建文件
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 jar 构建文件
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()
}
【问题讨论】:
标签: spring-boot gradle build.gradle executable-jar