Setting a filecollection that includes spaces as a classpath for JavaExec fails

I am trying to pass the compile configuration file collection as the classpath to a javaexec task that I have running. I have spaces in the file paths of some of the directories. I keep seeing failures when trying to execute my java executable because it cannot find class ‘Files’. This is 100% because there are no quotes around my classpath.

I ultimately have a command similar to: java -cp C:\Program Files (x86)\foo.jar com.foo.MainClass You can see that the java command is interpreting Files as my class because there are no quotes around the classpath argument.

I am on windows, developing a plugin in Java. I set my classpath by using the JavaExecSpec.setClassPath(FileCollection) method. Is this a bug? I can’t seem to find a way to make sure the classpath is properly set for the command.

Here is a small example of what I am trying to do and how it shows up after calling spec.getCommandLine():

Code

spec.setClasspath(project.files(
“c:/program files (x86)/ibm/sdp75/runtimes/base_v61/deploytool/itp/batch2.jar”,
“c:/program files (x86)/ibm/sdp75/runtimes/base_v61/deploytool/itp/batch2_n11.jar”)
.plus(project.getConfigurations().getByName(“compile”)));
spec.setMain(“com.ibm.etools.ejbdeploy.EJBDeploy”);

Output

c:\program files (x86)\ibm\sdp75\runtimes\base_v61\java\bin\java.exe
-cp
c:\program files (x86)\ibm\sdp75\runtimes\base_v61\deploytool\itp\batch2.jar;c:\program files (x86)\ibm\sdp75\runtimes\base_v61\deploytool\itp\batch2_n11.jar
com.ibm.etools.ejbdeploy.EJBDeploy

You can see how the classpath contains spaces that are not enclosed in quotes.