Skip to content
/ build-commons Public template

✨ Gradle plugins and catalog for Kotlin JVM, GraalVM and Multiplatform (Native/JS/WASM/WASI) development!

Notifications You must be signed in to change notification settings

sureshg/build-commons

Repository files navigation

🐘 Common Build Plugins

GitHub Workflow Status Maven Central Version OpenJDK Version Kotlin release

Gradle project and settings plugins that simplify bootstrapping Kotlin/Java projects targeting JVM, Multiplatform (Native/JS/Wasm/Wasi), and GraalVM native-image. These plugins handle configuring the most common build tasks, including:

  • Maven Central & GHCR publishing for artifacts & container images (Jib)
  • Code coverage for JVM and Kotlin Multiplatform projects
  • Project versioning (SemVer) based on Git tags
  • Code formatting to enforce consistent code style
  • Artifact signing
  • Java/Kotlin toolchain configuration
  • Target platform (JVM, JS, WASM, WASI, Native) configuration
  • Testing & reports
  • KSP & annotation processors
  • GraalVM Native image
  • Documentation (JavaDoc, Dokka)
  • Benchmarking (JMH)
  • Binary compatibility (ABI) validation
  • Deprecated API scanning (using jdeprscan)
  • Building truly executable JAR files
  • Build configuration generation
  • Version catalog to control artifact versions and build configurations
  • Automatic configuration of essential dependencies such as:
    • kotlinx-datetime
    • kotlinx-coroutines
    • ktor-client
    • kotlinx-serialization
    • kotlinx-io
    • Logging
  • Automatic configuration of compiler plugins such as:
    • redacted
    • kopy
    • power-assert
    • atomicfu
  • And many other common build tasks

These plugins help you focus on writing code, not configuring your build. They provide a solid foundation for your Kotlin/Java projects, handling the boilerplate and common tasks so you can get started quickly.

Development Environment Setup

  • Install Java 21 or later

    $ curl -s "https://get.sdkman.io" | bash
    $ sdk i java 21.0.6-zulu
  • Import the Gradle project. The initial sync may take some time as it downloads all dependencies.

Important

For the best and fastest experience, use the latest version of IntelliJ IDEA. Upgrade now!

Build & Testing

$ ./gradlew build

# Check dependency updates
$ caupain --gradle-stability-level=milestone

# OR
$ ./gradlew dependencyUpdates --no-configuration-cache

For testing, a separate sandbox project is available with the plugin and version catalog applied in settings.gradle.kts. First, publish the plugin to the local Maven repository, then run the sandbox project.

# Publish the plugins to Maven local
$ ./gradlew publishToMavenLocal

# Build the sandbox app using the published plugin
$ ./gradlew -p sandbox :build
$ sandbox/build/libs/sandbox

# Run other plugin tasks
$ ./gradlew -p sandbox :dependencyUpdates --no-configuration-cache
# To see the plugin classpath
$ ./gradlew -p sandbox :buildEnvironment | grep -i "dev.suresh"

Publishing

Push a new tag to trigger the release workflow and publish the plugin to Maven Central. That's it! 🎉 The next version will be based on the semantic version scope (major, minor, patch).

$ ./gradlew pushSemverTag "-Psemver.scope=patch"

# To see the current version
# ./gradlew v

# Print the new version
# ./gradlew printSemver "-Psemver.scope=patch"

# For a specific version
# git tag -am "v1.2.3 release" v1.2.3
# git push origin --tags

Published Plugins

Gradle Plugin ID Version
dev.suresh.plugin.root
dev.suresh.plugin.common
dev.suresh.plugin.graalvm
dev.suresh.plugin.kotlin.jvm
dev.suresh.plugin.kotlin.mpp
dev.suresh.plugin.kotlin.docs
dev.suresh.plugin.kotlin.benchmark
dev.suresh.plugin.publishing
dev.suresh.plugin.repos
dev.suresh.plugin.catalog

How to Use

  • Apply the following configuration to settings.gradle.kts of your project:

     pluginManagement {
        resolutionStrategy {
          eachPlugin {
            if (requested.id.id.startsWith("dev.suresh.plugin")) {
              useVersion("<plugin version>")
            }
          }
        }
    
        repositories {
          gradlePluginPortal()
          mavenCentral()
        }
     }
    
     plugins { id("dev.suresh.plugin.repos") }
  • Apply the required plugins to your root or sub project build.gradle.kts:

    // Kotlin JVM
    plugins {
      id("dev.suresh.plugin.root")
      id("dev.suresh.plugin.kotlin.jvm")
      id("dev.suresh.plugin.publishing")
      // id("dev.suresh.plugin.graalvm")
      application
    }
    
    // Kotlin Multiplatform
    plugins {
      id("dev.suresh.plugin.root")
      id("dev.suresh.plugin.kotlin.mpp")
      id("dev.suresh.plugin.publishing")
    }
    
    kotlin {
      jvmTarget(project)
      jsTarget(project)
      wasmJsTarget(project)
      wasmWasiTarget(project)
      nativeTargets(project) {}
    }
  • Use the version catalog by copying gradle/libs.versions.toml and changing the project-related metadata like group, app-mainclass, etc.

Important

Don't change the existing version names in the catalog as they are referenced by the plugins.

Verifying Artifacts

The published artifacts are signed using this key. The best way to verify artifacts is automatically with Gradle.

Misc

Maven Central Publishing

# Publish to local maven repository
$ rm -rf ~/.m2/repository/dev/suresh
$ ./gradlew publishToMavenLocal
$ tree ~/.m2/repository/dev/suresh

# Publish the plugins to maven central
$ ./gradlew publishToMavenCentral

Misc

# Update the Gradle Daemon JVM
$ ./gradlew updateDaemonJvm --jvm-version=21 --jvm-vendor=adoptium

References

About

✨ Gradle plugins and catalog for Kotlin JVM, GraalVM and Multiplatform (Native/JS/WASM/WASI) development!

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages