Issue
I'm trying setup my Gitlab CI/CD to compile and run tests for my Java/Maven/Spring Boot application. I've setup a Gitlab Runner and created my .gitlab-ci.yml and it all worked, but VERY SLOW. I've tried many configurations for my runner, without success.
So i made a step back and tried to run the tests on Docker on my local machine.
The build + tests running directly on my machine takes 17min. The build + tests running on docker takes more than 1h.
The best performance i've got was using using this docker command:
docker run -it --rm --name comp2 --mount type=bind,source="C:/ProjetosJava/eaud",destination=/usr/src/mymaven -e MAVEN_OPTS='-Xdebug -Xnoagent -Djava.compiler=NONE -Xmx4096m -Xms1024m -XX:MaxPermSize=1024m -Dmaven.repo.local=.m2/repository -XX:+TieredCompilation -XX:TieredStopAtLevel=1' -w /usr/src/mymaven maven:3.3-jdk-8 /bin/bash
and inside bash i did:
mvn -s .m2/settings.xml clean compile test
I need the build inside docker to have at minimun a close time (17min).
Solution
Found out the problem, it was the Maven Surefire plugin.
By default, surefire will fork the JVM, and when it do that it doesn't inherit the JAVA_OPTS from the mvn command.
So, i was i able to reduce the time of the build by configuring these configurations to the plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<java.awt.headless>true</java.awt.headless>
</systemPropertyVariables>
<argLine>-Xms256m -Xmx1024m -XX:MaxPermSize=512m -Xverify:none -XX:TieredStopAtLevel=1 -XX:-TieredCompilation</argLine>
<printSummary>false</printSummary>
<forkCount>0</forkCount>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
The secret is: argLine with -Xverify:none -XX:TieredStopAtLevel=1 -XX:-TieredCompilation
and forkCount=0
.
Answered By - renanleandrof
Answer Checked By - Mary Flores (JavaFixing Volunteer)