Multi-Gradle with Spring Boot Config Question

4 days ago 9
ARTICLE AD BOX

I'm looking for an explanation to why do I need to have a build.gradle in my service directory to stop the root build.gradle from treating it like a buildable project:

My Directory:

root: |-> services |-> gateway |-> (under the normal folder structure) GatewayApplication.java (Where my @SpringBootApplication is) |-> build.gradle |-> userService |-> UserServiceApplication.java (Where my @SpringBootApplication is) |-> build.gradle |-> build.gradle (the gradle file in question) |-> (root's) build.gradle |-> settings.gradle

My setting.gradle

rootProject.name = 'black-creek' // I thought that these would dictate that it where these directories, gateway and userService where the only buildable gradle projects include 'services:gateway' include 'services:userService'

root build.gradle:

plugins { id 'java' id 'org.springframework.boot' version '4.0.0' apply false id 'io.spring.dependency-management' version '1.1.7' apply false } allprojects { group = 'ciallsoftware' version = '0.0.1-SNAPSHOT' } subprojects { apply plugin: 'java' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' java { toolchain { languageVersion = JavaLanguageVersion.of(21) } } repositories { mavenCentral() } dependencies { developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { useJUnitPlatform() } }

Each of the service's projects have their own build.gradle for their specific dependencies. So I won't post those.

If I didn't include the build.gradle at the root of the service directory I'd continuously receive the following error:

./gradlew bR > Task :services:bootRun FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':services:bootRun'. > Failed to query the value of task ':services:bootRun' property 'mainClass'. > Main class name has not been configured and it could not be resolved from classpath

But I had discovered that the build.gradle was treating my service directory as a buildable project, even though I thought in the settings.gradle I dictated it was the subdirectories, i.e services:gateway, not the service directory. I had to include in the build.gradle in question:

bootJar { enabled = false } bootRun { enabled = false } jar { enabled = false }

I guess I just don't understand why it would treat my service directory as a buildable project, and why I would have to include what was printed just above this to prevent it. Any explanation / insight would be helpful.

Read Entire Article