Gradle multimodule with Spring Boot

I’m new to multimodule approach and I’d like to make it right.

I had an application with just one main module and it was easy in the way that all the definitions went to build.gradle.kts in the root of the project.

Now I wanted to turn it to multimodule project with buildSrc and suddenly where belongs what is not clear enough.

I wonder where to put following things and why:

  • definitions like
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(libs.versions.java.get())
    }
}

kotlin {
    compilerOptions {
        freeCompilerArgs.addAll("-Xjsr305=strict")
    }
}
  • basic SpringBoot variables like group and version which are applicable to whole project
  • definition of general tasks that should apply to all submodules - like sonar task

There are basically 3 candidate files:

  • build.gradle.kts in the root of the project
  • build.gradle.kts in the buildSrc dir
  • java-conventions.gradle.kts file in the buildSrc/src/main/kotlin dir

Can anybody explain where should things mentioned above go and why??
Thanks a lot!

I’m going to answer generically to instead make you understand things hopefully.

build.gradle.kts in the root of the project

Here go things that are only for the root project of the build, that can be configurations or it can also be convention plugins, for example written in buildSrc.

build.gradle.kts in the buildSrc dir

This is the build script of the plugin project where your convention plugin is built, so here go things that you need to build your plugin.

java-conventions.gradle.kts file in the buildSrc/src/main/kotlin dir

This is your convention plugin.

Actually, you should either rename it to have a dot somwhere in the name, or have a package statement inside, because plugin IDs without dot should stay reserved for built-in plugins.

But besides that, in that file go the things that make up your convention that you want applied wherever you apply that plugin.

Hello @Vampire, thank you for your reply and I also apology for very late response.

I eventually stayed with the single module solution because it’s just more simple, straightforward and my project is still small enough to keep things tidy. I will maybe return to it some day.

1 Like