I have a application. My application must run in Linux and Windows. I must write in main gradle-file any command. These commands content slash ("/" or "\"). How can I get what slash ("/" or "\") use (in language groovy)?
Asked
Active
Viewed 392 times
1
-
Typing "gradle file object" into Google gave me [this](http://www.gradle.org/docs/current/userguide/working_with_files.html) as the first hit. Google is your friend. In Java (and therefore Groovy) a `File` is platform agnostic - the delimiters will be sorted out automatically. – Boris the Spider Mar 18 '14 at 08:40
3 Answers
4
If you work with Java, you can freely use '/' as a file separator. java.io.File
will handle it for you. See similar SO question.
Gradle's file('Some\slashy/path')
is a shorthand for
new java.io.File("Some\slashy/path")
, and so deals with slashes correctly too.
-
2The `file` method does a lot more than that (e.g. it makes paths relative to the current project), but always using slashes is indeed the best solution. – Peter Niederwieser Mar 18 '14 at 14:10
0
You should use java.io.File.separator
instead of hard-coding it.
-
1It's not necessary to use `java.io.File.separator` for paths in Gradle build scripts. Instead, you can (and should) always use `/`. – Peter Niederwieser Mar 18 '14 at 13:51