Skip to content

Repository files navigation

Gradle Native Java Plugin

Until this becomes a standard feature in Gradle (gradle/gradle#34845), this plugin bridges the gap.

Gradle plugin for OS/architecture-aware and JVM-version-aware variant resolution in Java projects.

Automatically sets the following attributes on all configurations:

This enables Gradle to automatically select the correct variant of libraries that publish platform-specific or JVM-version-specific artifacts (e.g., esbuild-java).


Features

  • ✅ Safe to use with existing libraries — attributes are only used for variant matching if the library defines them.
  • ✅ Compatible with both Groovy and Kotlin DSL builds.
  • ✅ Automatically detects host OS and architecture.
  • ✅ No configuration required — just apply the plugin.

Usage

Kotlin DSL (build.gradle.kts)

plugins {
    id("io.mvnpm.gradle.plugin.native-java-plugin") version "1.1.2"
}

Groovy DSL (build.gradle)

plugins {
    id 'io.mvnpm.gradle.plugin.native-java-plugin' version '1.1.2'
}

If you need the same kind of resolution on plugins then you can do

Kotlin DSL (settings.gradle.kts)

plugins {
    id("io.mvnpm.gradle.plugin.native-java-settings-plugin") version "1.1.2"
}

Groovy DSL (settings.gradle)

plugins {
    id 'io.mvnpm.gradle.plugin.native-java-settings-plugin' version '1.1.2'
}

How It Works

When applied, the plugin sets the following attributes on all configurations:

  • org.gradle.native.operatingSystem — based on the current OS.
  • org.gradle.native.architecture — based on the current CPU architecture.

These attributes are used by Gradle’s variant-aware dependency resolution to select the correct artifact variant when available.


License

Apache License 2.0. See LICENSE for details.


Contributing

Pull requests and issues are welcome! If you find a bug or want to suggest a feature, feel free to open an issue.


Releasing

Prerequisites

GPG signing key

Add the following to ~/.gradle/gradle.properties (never commit this file):

signing.keyId=<last 8 chars of your GPG key ID>
signing.password=<your GPG key passphrase>

Generate a key if you don't have one:

gpg --gen-key
gpg --list-secret-keys --keyid-format SHORT  # note the key ID
gpg --keyserver keyserver.ubuntu.com --send-keys <keyId>

On macOS, GPG requires pinentry-mac to prompt for the passphrase:

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent

Gradle Plugin Portal credentials

Add to ~/.gradle/gradle.properties:

gradle.publish.key=<your portal API key>
gradle.publish.secret=<your portal API secret>

Get these from your account at plugins.gradle.org.

Publishing

./gradlew publishPlugins -PgradlePublish

About

Automatically sets "org.gradle.native.operatingSystem" and "org.gradle.native.architecture" attributes for variant resolution on JVM builds.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages