[GRADLE-2207] Allow application plugin start scripts to be more flexible for different environments. Created: 02/Apr/12  Updated: 02/Apr/15  Resolved: 02/Apr/15

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 2.4-rc-1

Type: Improvement
Reporter: Gradle Forums Assignee: Benjamin Muschko
Resolution: Fixed Votes: 5


 Description   

See linked forum topic, and pull request https://github.com/gradle/gradle/pull/77



 Comments   
Comment by Gradle Forums [ 02/Apr/12 ]

I haven't found I nice way myself, but something like this met my needs at the time:

startScripts << {
def lines = windowsScript.readLines().collect {
if (it ==~ /^set DEFAULT_JVM_OPTS=/) {
return 'set DEFAULT_JVM_OPTS=-Dapp.home="%~dp0.." -Dlogback.configurationFile=%~dp0..\config\logback.groovy'
} else {
return it
}
}
windowsScript.withPrintWriter { writer -> lines.each

{ writer.println it }

}
}

Comment by Gradle Forums [ 02/Apr/12 ]

Andrew is right, there is no direct way to do this right now.

I tend to use:

startScripts {
jvmOpts = "-Xmx1024m"
inputs.property("jvmOpts",

{ jvmOpts }) // for incremental build to work properly

doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
unixScript.text = unixScript.text.replace("$optsEnvVar=
startScripts {
jvmOpts = "-Xmx1024m"
inputs.property("jvmOpts", { jvmOpts }

) // for incremental build to work properly

doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
unixScript.text = unixScript.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
windowsScript.text = windowsScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}
quot;
startScripts {
jvmOpts = "-Xmx1024m"
inputs.property("jvmOpts",

{ jvmOpts }) // for incremental build to work properly

doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
unixScript.text = unixScript.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
windowsScript.text = windowsScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}
quot;", "$optsEnvVar=
startScripts {
jvmOpts = "-Xmx1024m"
inputs.property("jvmOpts", { jvmOpts }

) // for incremental build to work properly

doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
unixScript.text = unixScript.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
windowsScript.text = windowsScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}
quot;$jvmOpts
startScripts {
jvmOpts = "-Xmx1024m"
inputs.property("jvmOpts",

{ jvmOpts }

) // for incremental build to work properly

doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
unixScript.text = unixScript.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
windowsScript.text = windowsScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}
quot;")
windowsScript.text = windowsScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}

Comment by Gradle Forums [ 02/Apr/12 ]

Thanks for ideas Andrew and Luke! How would you guys feel about doing something like I mentioned similar to Tomcat?

For example in `unixStartScript.txt` around line 68, include this:

CLASSPATH=$classpath

if [ -r "setenv.sh" ]; then
. "setenv.sh"
fi

Comment by Gradle Forums [ 02/Apr/12 ]

I like the idea personally.

Comment by Gradle Forums [ 02/Apr/12 ]

Luke,

I created a pull request to update the templates:

[1]https://github.com/gradle/gradle/pull/77

Please take a look when you have a chance.

Thanks.
----------------------------------------------------------------------------------------
[1] https://github.com/gradle/gradle/pull/77

Generated at Wed Jun 30 12:15:38 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.