@Override public void execute(JavaExecSpec javaExec) { configureReloadAgent(javaExec); // mutates the launch context OutputStream fileOut = null; ObjectOutputStream oos = null; try { fileOut = new FileOutputStream(contextDestination); oos = new ObjectOutputStream(fileOut); oos.writeObject(launchContext); javaExec.setWorkingDir(launchContext.getBaseDir()); if (launchContext.getGrailsHome() != null) { javaExec.systemProperty("grails.home", launchContext.getGrailsHome().getAbsolutePath()); } File launcherJar = findJarFile(ForkedGrailsLauncher.class); javaExec.classpath(launcherJar); javaExec.setMain(Main.class.getName()); javaExec.args(contextDestination.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException(e); } finally { try { if (oos != null) { oos.close(); } if (fileOut != null) { fileOut.close(); } } catch (IOException ignore) { } } }