我开发了一个 controllerAdvice,我想把它放在一个可供多个微服务使用的库中;
由于我的库使用的是 spring 注释,因此我为 springboot 添加了插件和依赖项。但是当我添加
apply plugin: 'org.springframework.boot'
这在构建步骤中添加了一个 bootJar 步骤。 bootJar 要求我应该为 spring boot 设置一个主类,这也是我不想要的,因为我的 jar 只是一个库而不是 springboot 应用程序。
这是我的 gradle.build 脚本的一部分:
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.test'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
repositories {
mavenCentral()
maven {
url = artifactoryRepoUrl
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-configuration-processor")
compile("org.springframework.boot:spring-boot-starter-hateoas")
testCompile('org.springframework.boot:spring-boot-starter-test')
compileOnly('org.projectlombok:lombok:1.18.6')
annotationProcessor('org.projectlombok:lombok:1.18.6')
}
我该如何解决这个问题?
最佳答案
您需要做的就是禁用 bootJar
任务并启用 jar
任务(它创建一个普通的 jar 而不是一个可执行的 jar)。在 build.gradle 文件中添加以下代码段:
bootJar {
enabled = false
}
jar {
enabled = true
}
来源:https://spring.io/guides/gs/multi-module/
关于spring-boot - 使用 gradle 为 Spring Boot 创建一个库而不使用 bootJar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55730223/