@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) {

      }
    }
  }
  public void configureReloadAgent(JavaExecSpec exec) {
    if (springloadedJar == null) {
      return;
    }

    String agentJarFilePath = springloadedJar.getAbsolutePath();

    // Workaround http://issues.gradle.org/browse/GRADLE-2485
    Boolean isDebug = exec.getDebug();
    exec.jvmArgs(String.format("-javaagent:%s", agentJarFilePath), "-noverify");
    if (isDebug) {
      exec.setDebug(true);
    }
    exec.systemProperty("springloaded", "profile=grails");
  }