Home > Back-end >  Pass $ character to Gradle start scripts (Application plugin)
Pass $ character to Gradle start scripts (Application plugin)

Time:12-16

I have a Gradle build script that uses the Application plugin, and I want to pass as JVM argument a string that contains the $ character, but I can't because it always is converted to the \$ sequence of characters...

Here is my configuration:

application {
    mainClass = 'example.Main'
    application.applicationDefaultJvmArgs = ['-javaagent:$APP_HOME/lib/agent.jar']
}

But then in the start script I get:

DEFAULT_JVM_OPTS='"-javaagent:\$APP_HOME/lib/agent.jar"'

And because of that \ it doesn't work, I need the value to be -javaagent:$APP_HOME/lib/agent.jar. All ways I tried get the same result (using interpolation, passing the $ as \u0024, etc.).

CodePudding user response:

I've found a workaround in this answer for a related question. The code in question is the following:

startScripts {
    doLast {
        unixScript.text = unixScript.text.replace('\\$APP_HOME', '\$APP_HOME') 
        //do something like this for Windows scripts if needed too
    }
}
  • Related