I\'m working on a Spring Boot app with multiple modules and we\'re using Gradle to build it. Unfortunately I can\'t get the Gradle configuration right.
The project stru
The answer is similar to this one.
Gradle documentation on multi-project builds states:
A “lib” dependency is a special form of an execution dependency. It causes the other project to be built first and adds the jar with the classes of the other project to the classpath.
A repackaged jar, thus, poses a problem.
If, say, project B
depends on project A
, and the project A
has a org.springframework.boot
plugin applied to it, a simple compile project(':A')
dependency will not work because the project jar is repackaged during the bootRepackage
or bootJar
task. The resulting fat jar has different structure, preventing Gradle from loading its classes.
In this case, the dependencies should be written the following way:
dependencies {
compile project(':A').sourceSets.main.output
}
Using output of a source set directly is equivalent to using the "normal" resulting jar of project A
before it is repackaged.
bootJar {
enabled = false
}
jar {
enabled = true
}
This works for my. In my case use spring boot with spring cloud with multi project and gradle fail to build. With this solution works!
You should exclude org.springframework.boot
from all submodules (root build.gradle
file, allProjects
block), that are stands as dependencies for your core module, which will be build to fat-jar.
Include dependencyManagement
configuration into all of your spring-boot managed submodules:
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
}
}
The reason of your problem is the absence of submodules compiled jar files inside your core module fat-jar.
In your utility (data) projects put:
bootJar {
enabled = false
}
jar {
enabled = true
}
If kotlin dsl
tasks.getByName<BootJar>("bootJar") {
enabled = false
}
tasks.getByName<Jar>("jar") {
enabled = true
}