Hey everyone, I’m currently working with a Gradle ...
# community-support
a
Hey everyone, I’m currently working with a Gradle Kotlin project using the
buildSrc
directory to manage my conventions centrally. The project is structured as follows:
buildSrc/build.gradle.kts
This file defines the plugin dependencies and versions, for example:
Copy code
val kotlinVersion = "2.0.21"

plugins {
    `kotlin-dsl`
}

repositories {
    gradlePluginPortal()
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-gradle-plugin:3.3.11")
    runtimeOnly("io.spring.gradle:dependency-management-plugin:1.1.7")
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
    implementation("org.jetbrains.kotlin.plugin.spring:org.jetbrains.kotlin.plugin.spring.gradle.plugin:$kotlinVersion")
    implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8")
    implementation(platform("com.fasterxml.jackson:jackson-bom:2.19.0"))
}
buildSrc/src/main/kotlin/standard-convention.kts
This file contains standard configurations that I use as plugins across my modules or submodules. Here is an excerpt:
Copy code
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
    kotlin("jvm")
    kotlin("kapt")
    id("io.gitlab.arturbosch.detekt")
}

group = "com.example"
version = "0.0.1-SNAPSHOT"

repositories {
    mavenCentral()
}

detekt {
    config.setFrom("${rootProject.projectDir}/buildSrc/src/main/resources/detekt-config.yml")
    buildUponDefaultConfig = true
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8")

    testImplementation(platform("org.junit:junit-bom:5.12.2"))
    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType<KotlinJvmCompile>().configureEach {
    compilerOptions {
        jvmTarget.set(JvmTarget.JVM_21)
        freeCompilerArgs.add("-Xjsr305=strict")
    }
}

tasks.test {
    useJUnitPlatform()
}
Besides this, I also have other convention plugins that I use across different modules. I would now like to move my self-defined plugins into a separate project and publish them to a Git repository (or Maven repository), so that I can pull them as external dependencies into the modules that need them. Is there a recommended approach for this? Essentially, I want to decouple my plugins from
buildSrc
and manage them as independent, reusable Gradle plugins that can be versioned and shared across multiple projects. Thanks
p
Yes it absolutely is, but I would prefer a maven repo to publish the binaries instead of using git source code that needs to be compiled.
a
> Yes it absolutely is what exactly do you mean? > I would prefer a maven repo to publish the binaries instead of using git source code that needs to be compiled. do you have an example?
v
buildSrc
is a standalone build that "just happens" to be built before the main project and added to the build script class paths of the main build. You can just move the directory to a separate project directory, add a settings script if you don't have one and add
maven-publish
plugin to publish the project. Or you can also split it into multiple projects or builds if you want.