A detector for the OS name and architecture. It provides a uniform classifier to be used in the names of native artifacts.
This repository is an effort to provide functionalities the same as os-maven-plugin, but as a standalone artifact. It also redistributes the Maven plugin as well as the Gradle plugin (developed by Google) based on such a core lib to ensure the manner is the same.
I'm seeking for merging these three efforts into one. Check this issue for more information.
Currently, I'm actively maintaining this repository (lib
, plugin-maven
and plugin-gradle
) for publicly testing, as well as bugfixes + improvements. You can use it as a production-ready solution since the original logics are battle-tested over the years.
OS detector is provided as a normal module.
You can use it with Maven:
<dependency>
<groupId>com.tisonkun.os</groupId>
<artifactId>os-detector-core</artifactId>
<version>${os-detector.version}</version>
</dependency>
... or Gradle:
implementation("com.tisonkun.os:os-detector-core:$osDetectorVersion")
The common usage is:
public static void main(String[] args) {
final Detector detector = new Detector(/* ... */);
final Detected detected = detector.detect();
}
... where the Detected
structure is defined as:
public class Detected {
public final int bitness;
public final String version;
public final String classifier;
public final OS os;
public final Arch arch;
@Nullable
public final LinuxRelease linuxRelease;
}
You can use OS detector as a Maven extension:
<build>
<extensions>
<extension>
<groupId>com.tisonkun.os</groupId>
<artifactId>os-detector-maven-plugin</artifactId>
<version>${os-detector.version}</version>
</extension>
</extensions>
</build>
You can use OS detector as a Gradle plugin:
plugins {
id "com.tisonkun.osdetector" version "$osDetectorVersion"
}
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 available 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
.