Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


GRAILS-9271 - Parameter to specify download location for grails wrapper script #386

wants to merge 3 commits into from

3 participants


Attempt to address allowing user to specify wrapper.cache.dir in to override default user home location if needed.

@jeffbrown jeffbrown was assigned

I think this code throws an exception of wrapper.cache.dir is not defined and I think the default values for cacheDir and distUrl are reversed. Is all of that correct?


Looks like all of that statement is true. I can split out the call to the new method to take three params and check if the wrapper is null before calling getstring or do a null check ternary inline. Also the constants did get switched ( bad copy paste :) )

I can fix and resubmit, let me know.


If you can work up a rev tonight I will look at it tomorrow. Tomorrow is the last day to get changes in for RC2 which is likely the last RC before GA. Thanks.


Code changes per @jeffbrown


@ctoestreich Please open a new pull request that targets 2.4.x branch since master branch is now for Grails 3 development. Please also rebase your commits over the current head of 2.4.x branch.

@lhotari lhotari closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 9 deletions.
  1. +30 −9 grails-wrapper/src/main/java/org/grails/wrapper/
39 grails-wrapper/src/main/java/org/grails/wrapper/
@@ -21,6 +21,7 @@
+import java.lang.String;
import java.lang.reflect.Method;
@@ -40,21 +41,19 @@
public class GrailsWrapper {
+ private static final String DIST_URL = "";
+ private static final String USER_GRAILS_HOME = System.getProperty("user.home") + "/.grails/";
public static void main(final String[] args) throws Exception{
final ResourceBundle applicationBundle = ResourceBundle.getBundle("application");
final ResourceBundle wrapperBundle = ResourceBundle.getBundle("grails-wrapper");
final String grailsVersion = applicationBundle.getString("app.grails.version");
- String distUrl = wrapperBundle.getString("wrapper.dist.url");
- if (distUrl == null) {
- distUrl = "";
- }
- if (!distUrl.endsWith("/")) {
- distUrl += "/";
- }
+ final String distUrl = defaultAndPostFixConfigValue(DIST_URL, wrapperBundle, "wrapper.dist.url");
+ final String cacheDir = defaultAndPostFixConfigValue(USER_GRAILS_HOME, wrapperBundle, "wrapper.cache.dir");
- final File grailsHome = configureGrailsInstallation(distUrl, grailsVersion);
+ final File grailsHome = configureGrailsInstallation(distUrl, cacheDir, grailsVersion);
System.setProperty("grails.home", grailsHome.getAbsolutePath());
@@ -93,6 +92,26 @@ public static void main(final String[] args) throws Exception{
mainMethod.invoke(null, new Object[]{newArgsArray});
+ /**
+ * Method will use user value if set or use default value if not. Will also check for trailing '/' for url and dir style params.
+ * @param defaultValue default to use if user value not set
+ * @param userValue a value probably derrived from file
+ * @return string value to use
+ */
+ private static String defaultAndPostFixConfigValue(String defaultValue, ResourceBundle wrapperBundle, String propertyKey){
+ String finalValue = defaultValue;
+ if(wrapperBundle != null){
+ String userValue = wrapperBundle.getString(propertyKey);
+ if (userValue != null) {
+ finalValue = userValue;
+ }
+ }
+ if (!finalValue.endsWith("/")) {
+ finalValue += "/";
+ }
+ return finalValue;
+ }
private static void addSystemProperties(ResourceBundle wrapperBundle) {
String prefix = "systemProp.";
for (String key : wrapperBundle.keySet()) {
@@ -119,15 +138,17 @@ private static File findGroovyAllJar(final File directoryToSearch) {
* @param distUrl URL to directory where the distribution zip is found
+ * @param cacheDir directory to install grails files after download
* @param grailsVersion version of Grails to configure
* @return a File pointing to the directory where this version of Grails is configured
private static File configureGrailsInstallation(String distUrl,
+ String cacheDir,
final String grailsVersion) throws Exception {
final String src = distUrl + "grails-" + grailsVersion + ".zip";
final URI uri = new URI(src);
- final File grailsCacheDir = new File(System.getProperty("user.home") + "/.grails/");
+ final File grailsCacheDir = new File(cacheDir);
final File wrapperDir = new File(grailsCacheDir, "wrapper");
final File installDir = new File(wrapperDir, grailsVersion);
File downloadFile = null;
Something went wrong with that request. Please try again.