Ever had to look up operating system or architectu...
# community-news
y
Ever had to look up operating system or architecture details in a build script? Yes, it's PITA. You either have to fiddle with reading system properties (and half of the time you can never remember what the correct values are) OR you try to access the internal class
OperatingSystem
. Well, you don't have to suffer. You can have all that information (and more) with the Operating System plugin. It adds an extension called
OS
. What's new with the latest release? • There is a version that you can apply to
settings.gradle(.kts)
• If you work with variants you can even obtain the correct values you need for operating system and machine architecture. • If you need to look up values for OS/Arch for anything other that what Gradle is running on, you can do that do now via
getOsTypes()
and
getArchitectures()
. Hope it helps to resolve some pain for some of you. See the link for more details. os-gradle.ysb33r.org/operatingsystem-gradle-plugin/3.0.1/usage.html
v
Actually, there is also
Os
from Ant available which is not internal, and there is also the
osdetector
Gradle plugin by Google. :-)
y
I should put that in the docs as alternatives
t
Google has not historically been good at writing gradle plugins that follow best practices. Is that plugin good / maintained?
y
osdetector
last release 2023
👍 1
v
Didn't look at its source for quite a while, so don't remember. Maybe not.
y
v
♥️
Any reason you use separate IDs for the project and settings plugins?
y
I'm not aware that one could use the same.
v
Sure, just have it
Plugin<PluginAware>
, then check the argument type.
Works in settings, project, and also init
y
Thanks for the tip. I'm just wondering that if one uses the same id, then people might assume that exactly the same functionality is available in Project & Settings.
v
If you apply it to multiple projects, or to settings and project, does it redetect multiple times, or does it use e.g. a build service? Iirc the osdetector plugin detects for each project it is applied to separately.
y
Theoretically it should only detect once as it refers to
OperatingSystem.current()
internally which in turn just refers to an internal
static final
. Of course with different classloaders it might actually detect more than once. Actual code is here gitlab.com/ysb33rOrg/gradle/grolifant/-/blob/…/OperatingSystem.java?ref_type=heads and here gitlab.com/ysb33rOrg/gradle/grolifant/-/blob/…/OperatingSystemUtils.groovy?ref_type=heads
👌 1