Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to use forward slashes instead of File.separator in my (Gradle) build files?

Tags:

I don't see any obvious problems, but I'm wondering if it's ok to use / rather than File.separator when I'm writing my build files. Using File.separator makes it very difficult to read some of the paths. Ex:

dependsDir = "${buildDir}${File.separator}depends"

vs

dependsDir = "${buildDir}/depends"
like image 904
Ryan J Avatar asked Dec 29 '11 03:12

Ryan J


3 Answers

The forward slash (/) is a legal path separator on Windows, as well as Unix (including Linux and Mac OSX). So unless you need the build to run on other operating systems, it shouldn't be a problem.

like image 110
Avi Avatar answered Sep 21 '22 15:09

Avi


Gradle for the most part just relies on java.io.File to do all path related operations, which in turn gracefully handles / on both Windows and Linux. So using / in Gradle API is unlikely to cause any problems.

I am using / in a fairly large project which runs on both Windows and Linux, and so far I hadn't a single problem. Hope this helps.

like image 41
rodion Avatar answered Sep 21 '22 15:09

rodion


in File Class

 public static final String separator = "" + separatorChar;

where separatorChar is The system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\'.
and the separatorChar created from

static private FileSystem fs = FileSystem.getFileSystem();
public static final char separatorChar = fs.getSeparator();

For you based on your operating system the separator will be changed, while using File.separator.
by using / in your code, it won't support for other OS.

like image 36
Chandra Sekhar Avatar answered Sep 19 '22 15:09

Chandra Sekhar