[英]Maven Build Failure - Compiler Plugin
我正在嘗試在 Maven 中構建項目,但遇到以下錯誤:
[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]
項目的pom.xml為:
<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&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"
我的 $JAVA_HOME 設置為:
% echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-16.jdk/Contents/Home
我認為 Maven 不知道我正確的 javac 在哪里,但我不確定我需要在 pom.xml 文件中編輯/添加什么以確保它確實知道。 我驗證了 javac 是版本 16。
您需要Java 11來構建項目。 我能夠使用 JDK 11 在本地構建它。我使用了 maven 包裝器。 您可以嘗試使用以下命令。
./mvnw clean install
請在切換到 JDK 11 后重試,並確保簽出 master 分支。
我遇到過同樣的問題。 更改 lombok 版本對我有用。 我將我的龍目島版本更新到了最新版本。
解決步驟:
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 默認語言環境:en_IN,平台編碼:UTF-8 操作系統名稱:“mac os x”,版本:“10.15.7”,arch:“x86_64”,系列:“mac”
如果您的 Java 版本與我的案例 1.8 中的項目預期不同,則更改環境變量中的設置:
nano ~/.zshenv -> append "-v 1.8" 提及版本名稱。
這里.zshenv 文件:
導出 JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
導出 M2_HOME=/usr/local/Cellar/maven/3.8.1
導出 PATH=$PATH:$M2_HOME/bin
做源 ~/.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 默認語言環境:en_IN,平台編碼:UTF-8 操作系統名稱:“mac os x”,版本:“10.15.7”,arch:“x86_64”,系列:“mac”
您將看到版本更改為 1.8
現在構建項目。
我遇到了同樣的問題。 在我的情況下,mvn 使用的是 java 版本 17。項目所需的版本是 java 8。以以下方式設置插件配置沒有幫助。
<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>
它顯然只告訴 mvn 當前編譯器(在我的情況下為 java 17)將源代碼容納為 1.8,將目標代碼容納為 1.8。 mvn 實際用於編譯項目的 javac 仍然是 java 17。在我的特定情況下,這種安排不起作用,我遇到了有問題的錯誤。 我不得不指示 maven 使用屬於 java 8 安裝的 javac。 這是通過設置一個指向 java 主目錄的環境變量 JAVA_1_8_HOME 來實現的,正如我的 mac 系統上安裝的版本所揭示的那樣。 通過運行此命令/usr/libexec/java_home -V
找到的所需版本/Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home
已在 JAVA_1_8_HOME 環境變量中設置。 需要為maven-compiler-plugin
設置以下配置屬性。
<configuration> <verbose>true</verbose> <fork>true</fork> <executable>${env.JAVA_1_8_HOME}/bin/javac</executable> <compilerVersion>1.8</compilerVersion> </configuration>
檢查您的 java 版本是否與您的項目兼容
從官網下載jdk-11和apache-maven-3.8.6 ,更新java和maven路徑如下:(在mac中,輸入命令open.zshrc
並添加以下行)
export JAVA_HOME=/Users//Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
export M2_HOME=/Users//下載/apache-maven-3.8.6
導出 PATH=$PATH:$M2_HOME/bin
別名 mvn='$M2_HOME/bin/mvn'
導出 PATH=/opt/apache-maven-3.8.6/bin:$PATH
然后運行mvn clean compile
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.