Skip to content
/ build-commons Public template

✨ Gradle plugin and catalog for Kotlin JVM, GraalVM and Multiplatform (Native/JS/Wasm) 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 to simplify the bootstrapping of Kotlin/Java projects targeting JVM, Multiplatform (Native/JS/Wasm), and GraalVM native-image. The plugin will take care of configuring most common build tasks, including:

  • Maven central publishing for artifacts & Container image (Jib) of Kotlin/Java projects
  • Custom repo (GHCR) for artifacts and container images
  • Code coverage supporting JVM, Kotlin Multiplatform projects
  • Project Versioning (SemVer) based on Git tags
  • Code Formatting to enforce a consistent code style
  • Artifact Signing
  • Java/Kotlin Toolchains configuration
  • Target platforms (JVM, JS, WASM, Native) configuration
  • Testing & Reports
  • KSP & Annotation processors
  • GraalVM Native Image
  • Documentation (JavaDoc, Dokka)
  • Benchmarking (JMH)
  • API binary compatibility validation
  • Deprecated API scanning (using jdeprscan)
  • Builds truly executable JAR files
  • Build config 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 like
    • redacted
    • kopy
    • power-assert
    • atomicfu
  • And other common build tasks.

This plugin helps you focus on writing code, not configuring your build. It provides a solid foundation for your Kotlin/Java projects, handling the boilerplate and common tasks so you can get started quickly.

Dev Env 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 a better, faster experience, use the latest version of IntelliJ IDEA. Upgrade now!

Build & Testing

$ ./gradlew build

# Check dep updates
$ ./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 and then run the sandbox project.

$ ./gradlew publishToMavenLocal
$ ./gradlew -p sandbox :build
$ ./gradlew -p sandbox :dependencyUpdates --no-configuration-cache

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"

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

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 publishPluginMavenPublicationToMavenCentralRepository
    
    # Publish the catalog to maven central
    $ ./gradlew :catalog:publishToMavenCentral
    $ ./gradlew :catalog:publishAndReleaseToMavenCentral

References