0

The source code to reproduce the described behavior can be found in this repository.

It was originally created to test and solve problems when creating a Gradle Multi project.
Because of the multi project, the code is too extensive to be included in this question.
The funny thing is, the project works excellently in Eclipse. Both when starting as a Spring application and when running it from Eclipse on the local Tomcat.

However, if you want to build a WAR and call the Gradle war task, this message appears.

Working Directory: C:\Users\Martin Burchard\Entwicklung\2018\SpringRestart
Gradle User Home: C:\Users\Martin Burchard\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 4.3
Java Home: c:\Program Files\Java\jdk1.8.0_144
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: war

:SpringRestart-API:compileJava
:SpringRestart-API:processResources NO-SOURCE
:SpringRestart-API:classes
:SpringRestart-API:jar SKIPPED
:SpringRestart-Web:compileJavaC:\Users\Martin Burchard\Entwicklung\2018\SpringRestart\prj_web\src\main\java\de\mbur\SpringRestart\SpringRestartApplication.java:5: error: package de.mbur.mypage.domain does not exist
import de.mbur.mypage.domain.User;
                            ^
1 error
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':SpringRestart-Web:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
2 actionable tasks: 2 executed

I wonder why : SpringRestart-API: jar SKIPPED appears there.

Furthermore, I just noticed that in the API project only the dependencies from the main build.gradle appear. If I add additional dependencies to the API project, they will not be resolved. I thought io.spring.dependency-management was supposed to take care of it?

Update: it looks like the unsuccessful resolution of dependencies in the API project doesn't affect all dependencies. joda-time, for example, is resolved. commons-text only if you specify the version.

Nabor
  • 1,661
  • 3
  • 20
  • 45
  • You are adding a Spring Boot fat jar as a dependency to another project. That isn't going to work, see https://stackoverflow.com/questions/40089443/how-to-add-a-dependency-to-a-spring-boot-jar-in-another-project for more information on how to fix (or the specific section in the reference guide). – M. Deinum Nov 13 '17 at 12:06
  • What? No, I use `compile (project(":${rootProject.name}-API")){ transitive=false }` as in all my previous multi projects. The difference is that I also use `io.spring.dependency-management` this time. – Nabor Nov 13 '17 at 12:09
  • Which is a spring boot project, which will add the generated jar to your project. So yes you are adding the project which generates a jar as a dependency. According to your build file the spring boot plugin is applied to all subprojects, making them all spring boot projects. – M. Deinum Nov 13 '17 at 12:10
  • you said fat jar. In my previous projects all dependent projects where also added as jar to the war file but only the classes from the project, not from their dependencies. Fat jar means, that all dependencies also are put into the same jar. – Nabor Nov 13 '17 at 12:12
  • You are applying the spring boot jar to all your subprojects. Your API project is also a Spring Boot project... It will produce a fat-jar with a different structure and the classes aren't readable as a normal jar. If you want to produce a different jar you will need some additional steps in your API (or don't apply the Spring Boot plugin to all your projects but only the web project). – M. Deinum Nov 13 '17 at 12:14
  • got that, if I remove `apply plugin: 'org.springframework.boot'` from the subprojects section and only add it to the WEB project, then the dependency resolution from the subprojects section does not work any more for the API project – Nabor Nov 13 '17 at 12:17
  • And why should it... You haven't included a `dependencyManagement` section to include any bom (be it spring boot or the Spring IO platform, so there is nothing to manage) – M. Deinum Nov 13 '17 at 12:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158857/discussion-between-nabor-and-m-deinum). – Nabor Nov 13 '17 at 12:43

0 Answers0