java - Spring Boot gradle 多模块应用
问题描述
我有一个带有多个模块的 Spring Boot 应用程序(gradle),但是在构建应用程序时遇到了问题。下面是我的gradle
build.gradle(主应用程序)
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'net.sagati'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile project(':my-pet-clinic-data')
compile project(':my-pet-clinic-web')
}
test {
useJUnitPlatform()
}
build.gradle - 数据层。第一个模块
plugins {
id 'java'
}
group 'net.sagati'
version '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
}
test {
useJUnitPlatform()
}
bootJar {
enabled = false
}
jar {
enabled = true
}
build.gradle - web 层第二个模块
plugins {
id 'java'
}
group 'net.sagati'
version '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
}
test {
useJUnitPlatform()
}
bootJar {
enabled = false
}
jar {
enabled = true
}
********************错误信息 **************************** ************
A problem occurred evaluating project ':my-pet-clinic-data'.
> Could not find method bootJar() for arguments [build_iptt1011gxtkxqsop7ht18yc$_run_closure4@45139c47] on project ':my-pet-clinic-data' of type org.gradle.api.Project.
任何帮助,将不胜感激。
更新
删除后
bootJar {
enabled = false
}
我得到以下错误
Execution failed for task ':my-pet-clinic-data:compileJava'.
> Could not resolve all files for configuration ':my-pet-clinic-data:compileClasspath'.
> Could not find org.projectlombok:lombok:.
Required by:
project :my-pet-clinic-data
> Could not find org.springframework.boot:spring-boot-starter-data-jpa:.
Required by:
project :my-pet-clinic-data
解决方案
更新的问题是由于没有任何版本的依赖项引起的。
在应用 Spring boot Gradle 插件时,它会应用 Spring 依赖管理插件并配置 Spring boot BOM。这在文档中进行了解释。
但是,您的数据和 Web 项目仅应用java
插件,因此不支持 BOM。我建议查看原生 Gradle BOM 支持。可以在上面链接的 Spring 文档第 3.2 节中找到另一种具有性能成本的替代方法。
推荐阅读
- android - 收听点击展开的搜索视图字段
- cdi - 匕首可以获取注入点的上下文吗?
- fonts - 如何在电子中设置最小字体大小?
- ajax - ajax 成功后发送第二个 post 请求
- python - 如何在 Zenpy python 客户端库中将受让人设置为票证
- angular - 运行大约 1000 个单元测试后,无头 Chrome 断开连接
- java - 处理 ResourceServer 中的 spring 安全认证异常
- java - 每天没有收到本地警报通知
- django - Django Rest Framework:如何将嵌套关系的 UUID 列表传递给序列化程序?
- c++ - C ++静态工厂方法与构造函数:如何避免复制?