Spring boot and Gradle multi-modules project, failed to load dependencies correctly

依然范特西╮ 提交于 2020-08-08 05:27:21

问题


Basically I have a spring boot project build with Gradle. The project has a root project that contains another 4 sub-modules. The root project settings.gradle looks like this:

rootProject.name = 'proj'

include 'proj-app'
include 'proj-integration-tests'
include 'proj-model'
include 'proj-service'

The app module contains the spring-boot-gradle-plugin and exposes some api's.

What I wanted to do was to create proj-integration-tests sub-module that only contain the integration tests. The problem start here since I needed the proj-app dependency.

So in proj-integration-tests I have the build.gradle that contains:

dependencies {
  testCompile('org.springframework.boot:spring-boot-starter-web')
  testCompile('org.springframework.boot:spring-boot-starter-test')
  testCompile project(':proj-app')
  testCompile project(':proj-model')
}

and I needed the proj-app dependency since the integration test:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ProjApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

required the Spring boot application to start(ProjApplication.class) that is located in proj-app module.

The error that I got from Gradle is: "cannot find symbol ProjApplication".

Why Gradle could not manage properly the proj-app dependency? Thanks in advance ;)


回答1:


It seems that the proj-app dependency is build in a spring boot fashion way. This means that the artifact obtained is a executable spring boot far jar.This is why tha proj-integration-tests could not found the classes from proj-app at the compile time.
So in order to maintain the executable jar, and to have proj-app as a dependency in proj-integration-tests module, I've modified the build.gradle from proj app to create both jars: in a spring boot fashion way and the standard version:

bootJar {
baseName = 'proj-app-boot'
enabled = true
}

jar {
baseName = 'proj-app'
enabled = true
}


来源:https://stackoverflow.com/questions/50029812/spring-boot-and-gradle-multi-modules-project-failed-to-load-dependencies-correc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!