Maven clean install插件解析报错:求解难度及解决方案
clean install 非法反射访问警告问题解析 Hey there! Let's tackle your questions about that illegal reflective access warning you're seeing when running mvn clean install with OpenJDK 10 on Ubuntu 18.04.
1. 是否需要投入大量精力解决?
First off, this is not a rare, long-cycle problem—it's actually a pretty common warning introduced with Java 9's module system, which restricted access to internal JDK APIs that many older libraries/plugins used via reflection.
If your mvn clean install command is still completing successfully (i.e., the build finishes without a failure), you don't need to drop everything to fix this immediately. The warning is just a heads-up that some component is using deprecated, non-standard access patterns, but it doesn't break the build in most cases.
That said, if the warning is accompanied by an actual build failure, or you want to eliminate the noise (which is totally reasonable), fixing it is straightforward and won't take much time.
2. 解决方案
Here are actionable fixes you can try, ordered from most recommended to quick-and-dirty:
升级Maven插件版本
Most of these warnings come from outdated Maven plugins that haven't been updated to support Java 9+. Upgrading key plugins to their compatible versions will often resolve the issue. For example:
- Update
maven-compiler-pluginto 3.8.1 or later - Update
maven-surefire-pluginto 2.22.2 or later
Add or update these configurations in your pom.xml:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>10</source> <target>10</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.2.2</version> </plugin> </plugins> </build>
抑制警告(临时方案)
If you can't upgrade plugins right now, you can add JVM arguments to explicitly allow the reflective access, which will suppress the warning. Run Maven with these flags:
mvn clean install --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED
Or configure the arguments directly in your pom.xml for the compiler plugin:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>10</source> <target>10</target> <fork>true</fork> <compilerArgs> <arg>--add-opens java.base/java.lang=ALL-UNNAMED</arg> <arg>--add-opens java.base/java.io=ALL-UNNAMED</arg> </compilerArgs> </configuration> </plugin>
检查第三方依赖
Some third-party libraries might be using internal JDK APIs via reflection. Check if there are newer versions of these libraries that have been updated to comply with Java 9+'s module rules. Replace the old dependencies in your pom.xml with their latest compatible versions.
内容的提问来源于stack exchange,提问作者Threx

