45

I am trying to build a project in Maven and am experiencing the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project webgoat-container: Fatal error compiling: java.lang.ExceptionInInitializerError: Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @5d01a2eb -> [Help 1]

The pom.xml of the project is:

<modelVersion>4.0.0</modelVersion>
<groupId>org.owasp.webgoat</groupId>
<artifactId>webgoat-parent</artifactId>
<packaging>pom</packaging>
<version>8.2.1-SNAPSHOT</version>

<name>WebGoat Parent Pom</name>
<description>Parent Pom for the WebGoat Project. A deliberately insecure Web Application</description>
<inceptionYear>2006</inceptionYear>
<url>https://github.com/WebGoat/WebGoat</url>

<organization>
    <name>OWASP</name>
    <url>https://github.com/WebGoat/WebGoat/</url>
</organization>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.3</version>
</parent>

<licenses>
    <license>
        <name>GNU General Public License, version 2</name>
        <url>https://www.gnu.org/licenses/gpl-2.0.txt</url>
    </license>
</licenses>

<developers>
    <developer>
        <id>mayhew64</id>
        <name>Bruce Mayhew</name>
        <email>webgoat@owasp.org</email>
        <organization>OWASP</organization>
        <organizationUrl>https://github.com/WebGoat/WebGoat</organizationUrl>
    </developer>
    <developer>
        <id>nbaars</id>
        <name>Nanne Baars</name>
        <email>nanne.baars@owasp.org</email>
        <organizationUrl>https://github.com/nbaars</organizationUrl>
        <timezone>Europe/Amsterdam</timezone>
    </developer>
    <developer>
        <id>misfir3</id>
        <name>Jason White</name>
        <email>jason.white@owasp.org</email>
    </developer>
    <developer>
        <id>zubcevic</id>
        <name>René Zubcevic</name>
        <email>rene.zubcevic@owasp.org</email>
    </developer>
    <developer>
        <id>jwayman</id>
        <name>Jeff Wayman</name>
        <email/>
    </developer>
    <developer>
        <id>dcowden</id>
        <name>Dave Cowden</name>
        <email/>
    </developer>
    <developer>
        <id>lawson89</id>
        <name>Richard Lawson</name>
        <email/>
    </developer>
    <developer>
        <id>dougmorato</id>
        <name>Doug Morato</name>
        <email>doug.morato@owasp.org</email>
        <organization>OWASP</organization>
        <organizationUrl>https://github.com/dougmorato</organizationUrl>
        <timezone>America/New_York</timezone>
        <properties>
            <picUrl>https://avatars2.githubusercontent.com/u/9654?v=3&amp;s=150</picUrl>
        </properties>
    </developer>
</developers>

<mailingLists>
    <mailingList>
        <name>OWASP WebGoat Mailing List</name>
        <subscribe>https://lists.owasp.org/mailman/listinfo/owasp-webgoat</subscribe>
        <unsubscribe>Owasp-webgoat-request@lists.owasp.org</unsubscribe>
        <post>owasp-webgoat@lists.owasp.org</post>
        <archive>http://lists.owasp.org/pipermail/owasp-webgoat/</archive>
    </mailingList>
</mailingLists>

<scm>
    <url>https://github.com/WebGoat/WebGoat</url>
    <connection>scm:git:git@github.com:WebGoat/WebGoat.git</connection>
    <developerConnection>scm:git:git@github.com:WebGoat/WebGoat.git</developerConnection>
    <tag>HEAD</tag>
</scm>

<issueManagement>
    <system>Github Issues</system>
    <url>https://github.com/WebGoat/WebGoat/issues</url>
</issueManagement>

<ciManagement>
    <system>Travis CI</system>
    <url>https://travis-ci.org/WebGoat/WebGoat</url>
</ciManagement>

<properties>
    <!-- Use UTF-8 Encoding -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>

    <!-- This build number will be ubdated by Travis-CI -->
    <build.number>build</build.number>

    <!-- Shared properties with plugins and version numbers across submodules-->
    <activation.version>1.1.1</activation.version>
    <commons-collections.version>3.2.1</commons-collections.version>
    <commons-lang3.version>3.4</commons-lang3.version>
    <commons-io.version>2.6</commons-io.version>
    <guava.version>30.1-jre</guava.version>
    <lombok.version>1.18.4</lombok.version>
    <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
    <maven-failsafe-plugin.version>2.22.0</maven-failsafe-plugin.version>
    <maven-jar-plugin.version>3.1.2</maven-jar-plugin.version>
    <maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
    <maven-source-plugin.version>3.1.0</maven-source-plugin.version>
    <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
    <revision>8.2.0-SNAPSHOT</revision>
</properties>

<modules>
    <module>webgoat-container</module>
    <module>webgoat-lessons</module>
    <module>webgoat-server</module>
    <module>webwolf</module>
    <module>webgoat-integration-tests</module>
    <module>docker</module><!-- copy required jars in preparation of docker all-in-one build -->
</modules>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-exec</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>flatten-maven-plugin</artifactId>
            <version>1.2.5</version>
            <configuration>
            </configuration>
            <executions>
                <execution>
                    <id>flatten</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>flatten</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>11</source>
                <target>11</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <consoleOutput>true</consoleOutput>
                <failsOnError>true</failsOnError>
                <configLocation>config/checkstyle/checkstyle.xml</configLocation>
                <suppressionsLocation>config/checkstyle/suppressions.xml</suppressionsLocation>
                <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.14.0</version>
            <configuration>
                <targetJdk>11</targetJdk>
                <failurePriority>1</failurePriority><!-- 5 means fail even on the lowest priority, 0 means never fail -->
                <rulesets>
                    <!--suppress UnresolvedMavenProperty -->
                    <ruleset>${maven.multiModuleProjectDirectory}/config/pmd/pmd-ruleset.xml</ruleset>
                </rulesets>
                <failOnViolation>true</failOnViolation>
                <printFailingErrors>true</printFailingErrors>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>owasp</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.owasp</groupId>
                    <artifactId>dependency-check-maven</artifactId>
                    <version>5.3.2</version>
                    <configuration>
                        <failBuildOnCVSS>7</failBuildOnCVSS>
                        <skipProvidedScope>true</skipProvidedScope>
                        <skipRuntimeScope>true</skipRuntimeScope>
                        <suppressionFiles>
                            <!--suppress UnresolvedMavenProperty -->
                            <suppressionFile>
                                ${maven.multiModuleProjectDirectory}/config/dependency-check/project-suppression.xml
                            </suppressionFile>
                        </suppressionFiles>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

<repositories>
    <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

mvn -v output:

Maven home: /Users/tom/apache-maven-3.6.3
Java version: 16, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-16.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

And my $JAVA_HOME is set to:

% echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-16.jdk/Contents/Home

I believe that there is an issue with Maven not knowing where my correct javac is, but I'm not sure what I need to edit/add in the pom.xml file to make sure that it does know. I verified that javac is version 16.

eliteparakeet
  • 739
  • 1
  • 5
  • 14
  • Can you share the webgoat-container project's pom.xml as well? It seems the issue is while compiling that module. – Ajinkya Mar 31 '21 at 18:39
  • Please to to build your project first with JDK 11 because I suppose you have an issue related to Lombok... – khmarbaise Mar 31 '21 at 19:34

7 Answers7

56

Update your Lombok version to the latest.

Methmal Godage
  • 736
  • 1
  • 6
  • 12
  • 1
    I am super new to java and working through an older course for spring/spring boot. It was the only course that mentioned mongoDb(I need to learn that in the context of java :P). And this answer saved what remaining hair I have from being pulled out, lol. TY! – Int'l Man Of Coding Mystery Jul 25 '22 at 13:52
  • I used https://mvnrepository.com/artifact/org.projectlombok/lombok, to find the latest version (1.18.24 at this time), and changed my dependency from project `org.project:lombok` (no version because it was picked up from SpringParent `org.springframework.boot:spring-boot-starter-parent:2.1.0.RELEASE` to use `org.projectlombok.lombok:1.18.24`. In my case I think the problem was that the dependency wasn't properly defined. – PatS Dec 16 '22 at 17:53
  • Would have been impossible to find the solution if I hadnt bumped into this answer – Kalana Dananjaya Mar 23 '23 at 20:10
  • It runs in the IDE but doesn't compile with maven. What a nightmare of a bug. Thank you so much Methmal! For future reference v `1.18.26` proved to work. – Valerij Dobler Jun 24 '23 at 19:55
14

Steps to resolve :

  1. Do mvn --version :

Maven home: /Applications/apache-maven-3.8.1 Java version: 1.16.0_291, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

  1. If your Java version if different from what is project expecting like in my case 1.8 then change setting in environment variables:

nano ~/.zshenv -> append "-v 1.8" mention the version name.

here .zshenv file :

------------------------ ------------------------ 

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

export M2_HOME=/usr/local/Cellar/maven/3.8.1

export PATH=$PATH:$M2_HOME/bin
------------------------ ------------------------ 

Do source ~/.zshenv

Now check again :

 mvn --version

Maven home: /Applications/apache-maven-3.8.1 Java version: 1.8.0_291, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

You will see version is changed to 1.8

Now build the project.

Ruslan López
  • 4,433
  • 2
  • 26
  • 37
Vipul Gupta
  • 391
  • 2
  • 11
6

You need Java 11 to build the project. I was able to build it locally using JDK 11. I used maven wrapper. You can try using the following command.

./mvnw clean install

Please try again after switching to JDK 11 and make sure you checkout the master branch.

Varun Thakur
  • 214
  • 1
  • 6
4

I faced the same problem. In my case mvn was using java version 17. The desired version for the project was java 8. Setting up the plugin configuration in the following manner did not help.

          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.8.1</version>
              <configuration>
                 <source>1.8</source>
                  <target>1.8</target>
              </configuration>
          </plugin>

It apparently only tells mvn current compiler (in my case java 17) to accommodate source as 1.8 and target as 1.8. The javac which is actually used by mvn for compilation of the project is still java 17. This arrangement, in my particular case, was not working and I was getting the error in question. I had to instruct maven to use javac belonging to java 8 installation. This was achieved by setting an env variable JAVA_1_8_HOME pointing to java home as revealed by the versions installed on my mac system. The desired version /Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home, found by running this command /usr/libexec/java_home -V was set in the JAVA_1_8_HOME environment variable. The following configuration properties are required to be set for maven-compiler-plugin.

              <configuration>
                  <verbose>true</verbose>
                  <fork>true</fork>
                  <executable>${env.JAVA_1_8_HOME}/bin/javac</executable>
                  <compilerVersion>1.8</compilerVersion>
              </configuration>
Abhishek Prabhat
  • 917
  • 1
  • 6
  • 15
1

Download jdk-11 and apache-maven-3.8.6 from the official websites and update the java and maven paths as follows: (In mac, type the command open .zshrc and add the below lines)

export JAVA_HOME=/Users//Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home

export M2_HOME=/Users//Downloads/apache-maven-3.8.6

export PATH=$PATH:$M2_HOME/bin

alias mvn='$M2_HOME/bin/mvn'

export PATH=/opt/apache-maven-3.8.6/bin:$PATH

Then run mvn clean compile

  • 1
    You're using two separate paths. Don't keep used binaries and whatnot in user folders, they're bound to be deleted. – SimonC Nov 25 '22 at 08:19
1

In my case project Lombok had the wrong version. I took the latest and it fixed the problem.

Sven
  • 2,343
  • 1
  • 18
  • 29
0

check your java version if compatible with your project or not

Abdalrhman Alkraien
  • 645
  • 1
  • 7
  • 22