Hi!
Firstly, big thanks to all the heroes here; the ones with deep Gradle knowledge who devote so much time to help the rest of us learn!
My goal is to create a simple Gradle template for starting new projects according to how we’ve just started doing it in my team: programming back-end applications solely in Kotlin, using a multi-sub-project approach, and using Quarkus.
I have tried generating a new project with the Quarkus CLI, the IntelliJ Quarkus-Gradle wizard and the Gradle CLI, and gradle init
feels like the best tool so far (adding in Quarkus in a later step - dealing with those problems then…). The problem is that it uses the buildSrc
approach, but having studied the nowInAndroid project, along with the guides from Jendrik Johannes and an article from Tony Robalik, I want to go with an included “build-logic” build instead.
I tried to remove the buildSrc
folder and construct the build-logic project myself, but got stuck and haven’t found any leads anywhere for my situation.
Here is my intended project structure:
my-project/
├─ gradle/
│ ├─ build-logic/
│ │ ├─ kotlin-conventions/
│ │ │ ├─ src/
│ │ │ │ ├─ main/
│ │ │ │ │ ├─ kotlin/
│ │ │ │ │ │ ├─ my.project.kotlin-conventions-plugin.gradle.kts
│ │ │ ├─ build.gradle.kts
│ │ ├─ settings.gradle.kts
├─ app/
│ ├─ build.gradle.kts
├─ domain/
│ ├─ build.gradle.kts
├─ infrastructure/
│ ├─ build.gradle.kts
├─ settings.gradle.kts
These are the files I have started creating and filling out so far:
// ./settings.gradle.kts
pluginManagement {
includeBuild("./gradle/build-logic")
}
rootProject.name="my-project"
include("app", "domain", "infrastructure")
// We use a proprietary company repository, which we configure in the .gradle directory of our home folders
// ./gradle/build-logic/settings.gradle.kts
rootProject.name="build-logic"
include("kotlin-conventions")
// ./gradle/build-logic/kotlin-conventions/build.gradle.kts
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20")
}
// ./gradle/build-logic/kotlin-conventions/src/main/kotlin/my.project.kotlin-conventions-plugin.gradle.kts
plugins {
kotlin("jvm")
}
dependencies {
// This is where I get stuck. I cannot find the "implementation" method.
}
As commented in the last file, I get stuck because I don’t have access to the implementation()
method. I want to start defining the dependencies that all Kotlin code in my project will use, such as a common logging library.
I read that implementation()
is connected to the java
and java-library
plugins, but adding them do not solve my problem. Also, I am not planning to write any Java at all in this project, so it feels weird having to include them just to define dependencies (something that should not be exclusive to Java…). I got the impression that the kotlin("jvm")
plugin should provide the implementation()
method as well?
I am of course extremely open to any other details that you all might spot in my intended approach, that could be improved upon!
Thanks a lot to anyone willing to take a look!