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:
org.gradle.native.operatingSystem→ current OS (OperatingSystemFamily) (macos,linux,windows)org.gradle.native.architecture→ current architecture (MachineArchitecture) (x86-64,aarch64,x86)
This enables Gradle to automatically select the correct variant of libraries that publish platform-specific or JVM-version-specific artifacts (e.g., esbuild-java).
- ✅ 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.
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'
}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.
Apache License 2.0. See LICENSE for details.
Pull requests and issues are welcome! If you find a bug or want to suggest a feature, feel free to open an issue.
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-agentGradle 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.
./gradlew publishPlugins -PgradlePublish