【发布时间】:2021-03-11 22:34:44
【问题描述】:
我有一个包含以下 build.gradel 文件的多模块项目
核心:
repositories {
mavenCentral()
}
dependencies {
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
测试模块:
dependencies {
implementation project(":core")
}
应用程序:
repositories {
mavenCentral()
}
dependencies {
implementation project(":core")
implementation project(":test")
}
springBoot{
mainClassName = "com.yenovi.dev.Main"
}
然后是根:
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id "io.spring.dependency-management" version "1.0.4.RELEASE"
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'war'
}
repositories {
mavenCentral()
}
subprojects {
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: "io.spring.dependency-management"
apply plugin: 'org.springframework.boot'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
}
核心模块应该代表spring boot应用程序,测试模块通过创建一个通过依赖注入在Core中使用的服务来提供额外的功能。
app 模块有一个调用SpringApplication.run(Core.class, args); 的主类。我认为app 似乎没用,但最后,这个模块将被单独的项目替换,这些项目将使用来自这个项目的模块。
问题是这样test 的编译会失败,并出现一个错误,指出无法找到来自core 的包。经过一番谷歌搜索后,我发现将 spring boot 插件应用于所有模块会导致此问题,因为它禁用了 jar 任务。但是,如果没有该插件,构建将失败并出现错误,指出无法找到 spring boot starter web 依赖项,但我需要在所有模块中使用它,以便可以使用 @Service 注释之类的东西。
我该如何解决这个问题?
【问题讨论】:
标签: java spring-boot gradle module