Command line property is converted to path

I add a property with -PPROPERTYNAME=/m/abc/def to my build call.

When I try to use the property PROPERTYNAME in my build.gradle the value is magically converted to an absolute file path as I work under Windows and I have a drive with letter “M”. The value is converted to M:/abc/def but I just want to have it unconverted, just as a plain string.

How can I use it as plain string? I did not find a way. I use the Groovy version of the build.gradle script.

Here a small test project:
test.zip (60.4 KB)

Unpack it an run it with

./gradlew print

It will print /c/tmp which is what I expect.

Now add a property to the call like this:

./gradlew print -PDIR=/c/tmp

and you will get C:/tmp which is what I don’t expect. I just want to get /c/tmp.

Why is the string converted to an absolute system path when I use a property?

Attention: It must be run under Windows otherwise you will not see the effect.

That’s actually not a Gradle “problem”.
If you run what you said in a Cygwin shell it works perfectly fine.
If you run it from CMD, it works perfectly fine.
If you run it from PS, it works perfectly fine.
If you run it from Git Bash from Git for Windows, your behavior reproduces, so it is more an MSYS issue and a widely known one.

You can disable that behavior using the environment variable MSYS_NO_PATHCONV=1, so ´MSYS_NO_PATHCONV=1 ./gradlew print -PDIR=/c/tmp` for example outputs what you expect.