A Gradle plugin that detects the OS name and architecture, providing a uniform classifier to be used in the names of native artifacts.
It uses os-maven-plugin under the hood thus produces the same result.
Requires Java 8 or up.
The latest version 1.7.3
is available on Maven Central.
Its output is identical to os-maven-plugin:1.7.1
.
To use this plugin, include in your build script
plugins {
id "com.google.osdetector" version "1.7.3"
}
apply plugin: 'com.google.osdetector'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.7.3'
}
}
The plugin creates osdetector
extension in your project, through which you
can access the following attributes:
osdetector.os
: normalized OS nameosdetector.arch
: architectureosdetector.classifier
: classifier, which isosdetector.os + '-' + osdetector.arch
, e.g.,linux-x86_64
osdetector.release
: only vailable ifosdetector.os
islinux
.null
on non-linux systems. It provides additional information about the linux release:id
: the ID for the linux releaseversion
: the version ID for this linux releaseisLike(baseRelease)
:true
if this release is a variant of the given base release. For example, ubuntu is a variant of debian, so on a debian or ubuntu systemisLike('debian`)
returnstrue
.
WARNING: DO NOT USE osdetector.classifierWithLikes
because it has a
known issue. It
will be either removed or changed to a different form in the next version.
artifacts {
archives(artifactFile) {
classifier osdetector.classifier
type "exe"
extension "exe"
builtBy buildArtifact
}
}
other linux systems
def getLinuxReleaseSuffix() {
if (osdetector.release.isLike('debian')) {
return 'debian'
} else if (osdetector.release.isLike('redhat')) {
return 'redhat'
} else {
return 'other'
}
}
artifacts {
archives(artifactFile) {
classifier osdetector.classifier + '-' + getLinuxReleaseSuffix()
type "exe"
extension "exe"
builtBy buildArtifact
}
}
$ git clone [email protected]:google/osdetector-gradle-plugin.git
$ cd osdetector-gradle-plugin
$ ./gradlew install