Part of my GitLab CI pipeline uses Maven ( mvn test
). Maven fails to build my test project with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project GenericTests: Fatal error compiling: invalid target release: 13 -> [Help 1]
I did some research and apparently setting JAVA_HOME
to the location of JDK 13 would work, and it does, but only when I do it by hand locally via SSH.
In my pipeline, even if I export JAVA_HOME
right before running mvn test
I still get the same error.
script:
- export JAVA_HOME=/usr/java/jdk-13.0.2
- mvn test
Why does this work differently between GitLab CI and SSH? Could it have to do with the fact that GitLab CI is a non-interactive shell? What can I do to remedy this?
EDIT: I also tried to add a release
tag in pom.xml
like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>13</release>
</configuration>
</plugin>
but this only resulted in another error during build time:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project GenericTests: Fatal error compiling: invalid flag: --release -> [Help 1]
It turned out to be a mess-up on my part: mvn test
was being executed by means of an alias, which was actually sudo mvn test
. Hence why the environment variable wasn't being used and why I got Mojo permission denied errors locally when I tried to rerun tests.