Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply plugin in gradle conditional dependent on OS

Tags:

windows

gradle

I have added a plugin id "ua.eshepelyuk.ManifestClasspath" version "1.0.0" to plugins {} in my build.gradle file. I **would like to only run the plugin when using a windows computer. So what I tried is to add an if statement around the plugin. I have included Gradle plugin with my if statement below:

Build.graddle file:

plugins {
   if (System.getProperty("os.name").toLowerCase().contains("windows")) {
    id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
  }
}

When using the if statement above I get the error: 'only id(String) method calls allowed in plugins {} script block'. How can I fix this?

like image 681
HappyGoLucky Avatar asked Oct 30 '25 16:10

HappyGoLucky


1 Answers

Give below a try...

plugins {
    id "ua.eshepelyuk.ManifestClasspath" version "1.0.0" apply false
}

if(System.getProperty("os.name").toLowerCase().contains("windows")) {
    apply plugin: “ua.eshepelyuk.ManifestClasspath”
}
like image 64
Moon Avatar answered Nov 02 '25 23:11

Moon