"syntax error near unexpected token" error when JAVA_OPTS contains ")" character

Hi all,

When the JAVA_OPTS variable in my .bashrc file contains a round closing bracket “)” I get the following error when I try and run Gradle:

/usr/local/java/gradle-1.0/bin/gradle: eval: line 161: syntax error near unexpected token ')'
/usr/local/java/gradle-1.0/bin/gradle: eval: line 161: 'splitJvmOpts -Djavax.net.ssl.trustStore=/home/egrant/Documents/Work/jssecacerts -Djavax.net.ssl.trustStorePassword=changeit -Djavax.net.ssl.keyStore=/home/eddgrant_cert.p12 -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=MyPasswordContainsA)Character -Dorg.gradle.daemon=true'

My JAVA_OPTS declaration in my .bashrc file is as follows:

export JAVA_OPTS="-Djavax.net.ssl.trustStore=/home/egrant/Documents/Work/jssecacerts \
-Djavax.net.ssl.trustStorePassword=changeit \
-Djavax.net.ssl.keyStore=/home/eddgrantcert.p12 \
-Djavax.net.ssl.keyStoreType=pkcs12 \

When this happens Gradle seems to sit and cogitate for a few seconds whenever I ask it to do something, even if I’m using the daemon. It does then work correctly and execute the task I have requested but the wait, and the presence of the error, is rather annoying. If I remove the “)” character everything reverts back to normal and Gradle becomes marvellous once again.

Has anyone else encountered this? Any ideas as to a workaround (I’m unable to change my cert password to work around this otherwise that would be a workable temporary workaround).



Version details below:

Gradle 1.0
  Gradle build time: Tuesday, June 12, 2012 12:56:21 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.6.0_30 (Sun Microsystems Inc. 20.5-b03)
OS: Linux 3.0.0-21-generic amd64

Have you tried to escape the ‘)’ with a ‘’?

Sorry forgot to mention that, yes I have, it fixes the Gradle issue but it creates another issue in that my cert password seems to become invalid to things that use it such as Maven, which then spurts the following:

Error transferring file: java.security.NoSuchAlgorithmException:
Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl):
failed to decrypt safe contents entry: javax.crypto.BadPaddingException:
Given final block not properly padded

This had led me to the conclusion that the \ character wasn’t being treated as an escape character but rather as an additional literal \ character. I guess this makes sense since it’s a legal character to have in a Java String and isn’t a String terminator.

I’m curious to know it would need escaping for Gradle to work?

If not escaped, bash treats ‘)’ in the ‘gradle’ script as a bash meta character. Maybe it’s a problem with that script. I’ll open an issue for this. Meanwhile, you can try to set a ‘GRADLE_OPTS’ which does escape the ‘)’. If that still causes problems due to the unescaped character in ‘JAVA_OPTS’, you could edit the ‘gradle’ script to no longer consider ‘JAVA_OPTS’.

I’ve filed GRADLE-2361 for this.