I Love Gradle But...

I love Gradle as a build tool, it's so much nicer than Maven, XML is so 20th century. However, there are things about it I don't like, for example, I find the documentation opaque at best, it seems to be written by Gradle engineers for other Gradle engineers, not for the folks that actually use the tool.

Today, I got bitten by Gradle and I've just wasted an our trying to sort out the issue.

What I have is a multi-module project, something that I think would be very common, but again I find the documentation for it lacking. In this project I have three 'modules', let's call them app1, app2 and shared.

In my top-level project I have a build.gradle.kts, a gradle.properties and a gradle.settings.kts file. Each sub-project had a build.gradle.kts and a gradle.settings.kts file. I'm also using a TOML file to store the application references. THIS ALL WORKED YESTERDAY!!

Today, after running one of the applications I went to tun the app again, under the debugger and 'weird' things started to happen.

The first thing I noticed was that my 'run' configuration had gone missing from IntelliJ Idea, ok, odd, but I thought I'd seen something similar in the past. If I have the same project open on two machines then sometimes the configurations clash. No problem, I'll just go and re-add the configuration. So I add the configuration and go to use it and it's disappeared again.

Now I think it's because I've renamed one of the sub-projects so the configuration name doesn't match the sub-project name, no worries, go to the Gradle window, scroll down to the Tasks, find the 'application' task and hit 'run', now I start getting errors in the build.gradle.kts file. The file looked like this

plugins {
    alias(libs.plugins.kotlinJvm)
    alias(libs.plugins.kotlinSerialization)
    application
}

group = "com.knowledgespike"
version = "1.0-SNAPSHOT"


application {
    mainClass.set("com.knowledgespike.teamvteam.Application")

    applicationDefaultJvmArgs = listOf("-Dlogback.configurationFile=./logging/logback.xml")
}

kotlin {
    jvmToolchain(17)
}

And the error I was getting was:

Unresolved reference: libs which was just wrong as I used these references in other projects. OK, so I think I'm being an idiot, clean the file down to a minimum so that there are no more Gradle compilation errors and try running the application and I get

Could not find or load main class com.knowledgespike.teamvteam.Application

It couldn't find the class, like I said THIS WORKED YESTERDAY!! In fact it had worked 30 minutes previously.

I also noticed other strange behaviour, for example, one of the Gradle sub-projects downloaded it's own version of Gradle (8.4, I'm running on 8.5), and the sub-projects were not building unless I ran 'build' from the top-level project.

So what was the issue, well, it was me being stupid but not in an obvious way, as I said THIS WORKED YESTERDAY!! Turns out sub-projects can't have settings.gradle.kts files. Now, I think I knew this but I'd obviously forgotten. Deleting those files clears up all the issues.