Executing JavaExec task with jar doesn't take care of arguments

(jbi) #1

Hi there,

I want to execute a local jar-file with two arguments. My code looks like that:

task jsMinify(type: JavaExec) {
main = '-jar’
args “${devLibs}/yuicompressor-2.4.2.jar”, “test.js”, “-o test-min.js”

When I execute the task I get the following output (with --info):

Starting process ‘command ‘<…>\jdk1.6.0_45\bin\java.exe’’. Working directory: <…>\workflow Command: <…>\jdk1.6.0_45\bin\java.exe -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -jar etc/development-libs/yuicompressor-2.4.2.jar test.js -o test-min.js
Successfully started process ‘command ‘<…>\jdk1.6.0_45\bin\java.exe’’
> Building 0% > :jsMinify
Usage: java -jar yuicompressor-x.y.z.jar [options] [input file]

Global Options
  -h, --help                Displays this information
  --type <js|css>           Specifies the type of the input file
  --charset <charset>       Read the input file using <charset>
  --line-break <column>     Insert a line break after the specified column number
  -v, --verbose             Display informational messages and warnings
  -o <file>                 Place the output into <file>. Defaults to stdout.
JavaScript Options
  --nomunge                 Minify only, do not obfuscate
  --preserve-semi           Preserve all semicolons
  --disable-optimizations   Disable all micro optimizations
If no input file is specified, it defaults to stdin. In this case, the 'type'
option is required. Otherwise, the 'type' option is required only if the input
file extension is neither 'js' nor 'css'.
:jsMinify FAILED
:jsMinify (Thread[Daemon worker Thread 9,5,main]) completed. Took 0.236 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jsMinify'.
> Process 'command '<..>\jdk1.6.0_45\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

The final command obviously is the following:

<…>\jdk1.6.0_45\bin\java.exe -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -jar etc/development-libs/yuicompressor-2.4.2.jar test.js -o test-min.js

When I execute the command manually, the execution is successful.

It seems to me like the arguments are not recognized. The current output (like --help) usually only appears if the arguments are wrong / not set.

(jbi) #2

Okay. Got it. The argument key and value must be several items in the args array.

Instead of:

args “${devLibs}/yuicompressor-2.4.2.jar”, “test.js”, “-o test-min.js”

it must be

args “${devLibs}/yuicompressor-2.4.2.jar”, “test.js”, “-o”, “test-min.js”

Reference: JavaExec args are not interpreted by the java command