title: Setting JAVA_OPTS and JAVA_TOOL_OPTIONS in Gradle
body: <p>Running a large Gradle build (with JDK7) I receive two <code>OutOfMemoryErrors</code>:</p>
  
  <pre><code>Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
  Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Test worker" 
  </code></pre>
  
  <p>When I set the two environment variables below, the build runs through and works just fine:</p>
  
  <pre><code>export JAVA_OPTS="-Xmx2048m -XX:MaxPermSize=1024m"
  export JAVA_TOOL_OPTIONS="-Xmx1024m -XX:MaxPermSize=1024m -Xms768m"
  ./gradlew test --stacktrace
  ...
  Picked up JAVA_TOOL_OPTIONS: -Xmx1024m -XX:MaxPermSize=1024m -Xms768m
  ...
  </code></pre>
  
  <p>Is there a way to include those settings in <code>gradle.properties</code> or in <code>build.gradle</code>? If yes, what is the correct usage?</p>
  
  <p>I already tried this in <code>build.gradle</code>:</p>
  
  <pre><code>allprojects {
      System.setProperty('JAVA_OPTS', "-Xmx2048m -XX:MaxPermSize=1024m")
      System.setProperty('JAVA_TOOL_OPTIONS', "-Xmx1024m -XX:MaxPermSize=1024m -Xms768m")
  }
  </code></pre>
  
  <p>but that doesn't work.</p>