2

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 ;)

brebDev
  • 774
  • 10
  • 27
  • Is `ProjApplication` in a package? And I assume the error you're seeing is while compiling the integration tests, correct? Either `ProjApplication` is in the default package, which means it's not visible to classes in a package, or the app's JAR is not being added to the `archives` configuration. – Peter Ledbrook Apr 26 '18 at 09:17
  • Also, why not have the integration tests in `proj-app`? You then don't have to wait for the app to be packaged before the integration tests run. Although that does depend on the nature of the integration tests. – Peter Ledbrook Apr 26 '18 at 09:18
  • ProjApplication is located under the proj-app package. Yes you're right the error is thrown during the compilation of integration test. The IDE does not seem to complain about it, but when I'm building the proj from the cli the error appear. – brebDev Apr 27 '18 at 08:54
  • I want to have a different module that only contains the integration-tests, since the testers will have access also to this module, and I think it's much nicer in this way. – brebDev Apr 27 '18 at 08:57
  • OK, fair enough. So, what version of Gradle are you using? Are the integration tests under _proj-integration-tests/src/test/java_? Are you running `gradle test` in the integration test project? Is the project dependency appearing when you run `gradle :proj-integration-test:dependencies --configuration testCompileClasspath`? – Peter Ledbrook Apr 27 '18 at 09:08
  • Hey thx for your answers, it seems that the proj-app artifact was an executable fat jar spring boot, and the proj-integration-test needed as dependency a standard version. Cheers! – brebDev May 01 '18 at 14:38

1 Answers1

10

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
}
brebDev
  • 774
  • 10
  • 27