Question

Using the application task I am specifying:

applicationDefaultJvmArgs = ['$DEBUG_OPTS',
  '-Djava.library.path=${ZMQ_LIB_PATH}']

In the generated start scripts I see:

DEFAULT_JVM_OPTS='"\$DEBUG_OPTS" "-Djava.library.path=\${ZMQ_LIB_PATH}"'

I don't want the \$ in there. I tried using '$$DEBUG_OPTS' and also '\$DEBUG_OPTS' but got the same result. What is the right way to escape the $ so it ends up in the script without a backslash in front of it?

Was it helpful?

Solution 2

The StartScriptGenerator code implies that '$' will be unconditionally replaced by the '\$'.

I assume that your intention is to use '$' character for shell parameters extension but I would like to point out that such usage (if permitted by the gradle task that generates the scripts) is not interoperable between bash and bat scripts - in the bash it will be used for shell parameters extension but in the bat it will have no meaning.

OTHER TIPS

I had a similar issue, trying to add a commandline parameter $1 in there. With some googling came up with this solution, fixing the script after the fact.

applicationDefaultJvmArgs=['-Dmy.property=DOLLARONE']

...

startScripts{
    doLast{
        def bashFile = new File(getOutputDir(),applicationName)
        String bashContent = bashFile.text
        bashFile.text = bashContent.replaceFirst('DOLLARONE',       Matcher.quoteReplacement('$1'))
    }
}

For Kotlin build script the solution could look like:

tasks.named<CreateStartScripts>("startScripts") {
    doLast {
        unixScript.writeText(unixScript.readText().replace("{{APP_HOME}}", "\${APP_HOME}"))
        windowsScript.writeText(windowsScript.readText().replace("{{APP_HOME}}", "%APP_HOME%"))
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top