When I run Spring Boot application from Eclipse (STS) as 'Java Application' or as 'Spring Boot App' the app fails because it tries to load configurations (@Configuration) from test classpath.
The thing is that it works for maven based builds correctly, but not for gradle.
The only workaround I see is to rename test package to something else to hide it from classpath scanning.
Overall the question is - how to make it work properly? I'd assume that SpringToolSuite team encounters this problem on a daily basis or I do something incorrectly.
Here's a test project which works when imported as maven, but fails when imported as gradle: https://github.com/mabn/spring-boot-integration-test
- Here's a year-old STS issue - is it still relevant?
- Here's another one marked as resolved
- Similar question about maven projects
I'm using STS 3.7.1
The thing is that it works for maven based builds correctly, but not for gradle.
Yes, unfortunately that is the case. Gradle doesn't deal properly with configuring eclipse's runtime classpath at all. This is even the case with Gradle's own new BuildShip eclipse plugin.
See this issue I recently raised:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482315
The resolved bug you found is indeed resolved, but it only concerned the maven/m2e case, which is in fact fixable (m2e does this correcty for "Run As >> Java Project" and we adopted a similar fix for "Run As >> Spring Boot App"). However, that fix is maven-specific as the gradle case is not really fixable until this Gradle tooling-api issue ticket is resolved:
https://issues.gradle.org/browse/GRADLE-1777
I had to introduce separation with profiles for this.
Having all test marking with
@ActiveProfiles("srv-test")
and main configuration with @Profile({"local", "docker"})