title: Gradle Heap Space Problems with big Standard Output
body: <p>When I build my project with gradle, the test outputs are huge and I would like to keep them. Therefore, I activated showing the output streams:</p>
  
  <pre><code>test {
      testLogging.showStandardStreams = true
  }
  </code></pre>
  
  <p>Unfortunately, gradle does not seem to be able to handle big standard outputs. For demonstration, I created a minimal example: <a href="https://github.com/DaGeRe/stdout-test" rel="nofollow noreferrer">https://github.com/DaGeRe/stdout-test</a> It is a project creating big standard output in a test by </p>
  
  <pre><code>@Test
  public void test() {
     long start = System.currentTimeMillis();
     for (int i = 0; i &lt; 200; i++) {
        for (int j = 0; j &lt; 10000; j++) {
           long current = System.currentTimeMillis() - start;
            System.out.println("This is a simple logging output: " + i + " " + j + " " + current);
        }
     }
  }
  </code></pre>
  
  <p>If I run this in a standard maven project, it finishes in about 2 minutes:</p>
  
  <pre><code>reichelt@reichelt-desktop:~/workspaces/stdout-test$ time mvn test &amp;&gt; mvn.txt
  
  real    1m34,130s
  user    0m31,333s
  sys     1m12,296s
  </code></pre>
  
  <p>If I run it in gradle by <code>time ./gradlew test &amp;&gt; gradle.txt</code>, it does not finish at all (in reasonable time) and the output contains many <code>Expiring Daemon because JVM heap space is exhausted</code>. A way to solve this temporarily would be increasing heap memory (like suggested here: <a href="https://stackoverflow.com/questions/53854198/jvm-space-exhausted-when-building-a-project-through-gradle">JVM space exhausted when building a project through gradle</a> ), but <code>-Xmx4g</code> does not change anything according to my experiments, and this obviously will not scale for bigger outputs. Also, running <code>./gradlew -i test</code> does not change the behavior.</p>
  
  <p>The project also contains example files for outputs from maven (<a href="https://github.com/DaGeRe/stdout-test/blob/master/mvn.txt" rel="nofollow noreferrer">https://github.com/DaGeRe/stdout-test/blob/master/mvn.txt</a>) and gradle (<a href="https://github.com/DaGeRe/stdout-test/blob/master/gradle.txt" rel="nofollow noreferrer">https://github.com/DaGeRe/stdout-test/blob/master/gradle.txt</a> - aborted process after ~10 minutes) and one of the heap dumps (<a href="https://github.com/DaGeRe/stdout-test/blob/master/java_pid10812.hprof.tar" rel="nofollow noreferrer">https://github.com/DaGeRe/stdout-test/blob/master/java_pid10812.hprof.tar</a>) gradle created. There are only minor increases in the current time in the gradle-log (third output number of every line). Therefore, I assume that gradle mainly has problems printing to stdout and not executing the program.</p>
  
  <p>This shows that, while gradle has some problems printing to stdout, it seems to not block the test execution. Is there any switch or parameter I could give gradle, which forces gradle to directly print to stdout instead of doing its memory-intense processing? Unfortunately, I did not find any in the documentation (<a href="https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html" rel="nofollow noreferrer">https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html</a>). </p>
  
  <p><strong>EDIT</strong> Just finished a test run on a server:</p>
  
  <pre><code>reichelt@r147:~/workspaces/dissworkspace/stdout-test$ time ./gradlew test &amp;&gt; gradle.txt
  
  real    28m17,959s
  user    216m37,351s
  sys     0m12,410s
  </code></pre>
  
  <p>Ends with an exception:</p>
  
  <pre><code>    This is a simple logging output: 89 7842 1416
      This is a simple logging output: 89 7843 1416
      This is a simple logging output: 89 7844 1416
      This is a simple logging output: 89 7845 1416
      This is a simple logging output: 89 7846 1416
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  GC overhead limit exceeded
  </code></pre>