JavaExec: args with blanks and "

Using the JavaExec I want to execute this command:

java -cp %JBOSS_HOME%\jboss-modules.jar ^
org.jboss.modules.Main ^
-mp %JBOSS_HOME%\modules org.jboss.as.cli -c --command="deploy build/libs/shop.war --force"

I tried the following settings without success. Any hint is appreciated!

classpath = configurations.deploy
main = 'org.jboss.modules.Main'
args '-mp', "${System.getenv('JBOSS_HOME')}/modules", 'org.jboss.as.cli', '-c', '--command="deploy build/libs/shop.war --force"'

What happens exactly? What’s the error message?

I’m getting this error message:

:deploy
INFO  [org.jboss.modules] JBoss Modules version 1.4.3.Final
'build/libs/shop.war' is assumed to be a command(s) but the commands to execute have been specified by another argument: [deploy]
:deploy FAILED

It’ just the same like doing the wrong invocation:

java -cp ... --command=deploy build/libs/shop.war --force

Instead of the correct invocation:

java -cp ... --command="deploy build/libs/shop.war --force"

However, I don’t know where the " is lost.

I’m assuming you are running under Windows, in which case it looks like https://issues.gradle.org/plugins/servlet/mobile#issue/GRADLE-2779
See JavaExec and quotes on Windows

Yes, I’m running on Windows. In fact it looks like https://issues.gradle.org/browse/GRADLE-2779.
When I’m using

args ..., '--command="deploy build/libs/shop.war --force"'

then the quote is lost. Also when using " instead of ".
However, when I’m using

args ..., '--command=""deploy build/libs/shop.war --force""'

then both quotes remain. Also when using " instead of ".
Therefore, I cannot deploy a Java EE app to WildFly aka JBoss when running on Windows…
BTW, the same issue happens when I try to use the ANT plugin for executing the Java class.

I got my Wildfly 8 working by adding “\x22” instead of the quotes.

Example:
–command=\x22deploy PATH --all-server-groups\x22

I am facing the same problem with wildfly 10 when I am executing undeploy command using groovy script as below

‘{Wildfly_home}/bin/jboss-cli.sh -c --command=“undeploy {earfile}”’.execute()

The error I received is as below
’***.ear"’ is assumed to be a command(s) but the commands to execute have been specified by another argument: ["undeploy]

Can anyone help me with this? I tried with escape quotes as well but of no use