Maven compilation issue with Java 9
Solution 1:
Just add this
<forceJavacCompilerUse>true</forceJavacCompilerUse>
to your maven compiler build plugin in your POM and you'll see all the javac errors! Source with more details
Solution 2:
Debugging
Step one should be to add the maven-compiler-plugin and enable
<forceJavacCompilerUse>true</forceJavacCompilerUse>
as the top answer suggests.
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
</plugin>
...
This will point out the actual compilation error.
[main] INFO org.apache.maven.plugin.compiler.CompilerMojo - -------------------------------------------------------------
[main] ERROR org.apache.maven.plugin.compiler.CompilerMojo - COMPILATION ERROR :
[main] INFO org.apache.maven.plugin.compiler.CompilerMojo - -------------------------------------------------------------
[main] ERROR org.apache.maven.plugin.compiler.CompilerMojo - last round: true
/home/vsts/work/1/s/src/main/java/com/company/services/TemplateService.java:[3,61] error: cannot find symbol
symbol: class VariableNotFoundException
Root Cause
For me the root cause was that I made a commit and pushed it to the server which triggered CI, but did not include one class in the commit that was being used somewhere. Hence the compiler was not able to find it in the CI environment.
throws VariableNotFoundException {
The solution is to make sure you don't have any Git staged files that you forgot to include as part of your commit.