1

I develop locally in a Windows PC and I have my build machine in OSX and or Linux. Since some of the files have over 255 characters I changed my build path like this:

buildDir = "C:/tmp/${rootProject.name}/${project.name}"

Now this won't work in any UNIX system. How can I make it dynamic so it works in Windows, OSX and Linux? I am trying to find a variable but I dont have that much experience in gradle.

sebastianf182
  • 9,844
  • 3
  • 34
  • 66

2 Answers2

1

You can use the Os class from ant

Try something like this :

import org.apache.tools.ant.taskdefs.condition.Os

def prefix = Os.isFamily(Os.FAMILY_WINDOWS) ? 'C:/' : '/'
buildDir = prefix + "tmp/${rootProject.name}/${project.name}"
ToYonos
  • 16,469
  • 2
  • 54
  • 70
  • Awesome. I only had to change the single quotes to double quotes so the variables get replaced but this worked. Thanks! – sebastianf182 Mar 29 '18 at 17:04
0

Gradle is built on top of Groovy, which is a JVM language just like Java. Therefore, you can use the same method(s) you can use in Java.

Lukas Körfer
  • 13,515
  • 7
  • 46
  • 62