META-INF/versions/9/module-info.class 冲突问题解决

Posted 哈拉少

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了META-INF/versions/9/module-info.class 冲突问题解决相关的知识,希望对你有一定的参考价值。

最近改造自动化工程,想引入国外的自动化框架:selenide.
发现引入jar包后,一直报包冲突。
看了下是 maven 的一个冲突检测插件抛出的异常

 <groupId>org.apache.maven.plugins</groupId>    
 <artifactId >maven-enforcer-plugin</artifactId>    
 <version>1.4.1</version>    
 

具体错误如下:

NFO] Adding ignore: com.sun.jna.*
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.BanDuplicateClasses failed with message:
Duplicate classes found:

Found in:
org.seleniumhq.selenium:selenium-ie-driver:jar:3.141.59:test
org.seleniumhq.selenium:selenium-edge-driver:jar:3.141.59:test
org.seleniumhq.selenium:selenium-chrome-driver:jar:3.141.59:test
org.seleniumhq.selenium:selenium-opera-driver:jar:3.141.59:test
org.seleniumhq.selenium:selenium-remote-driver:jar:3.141.59:test
org.seleniumhq.selenium:selenium-api:jar:3.141.59:test
org.seleniumhq.selenium:selenium-firefox-driver:jar:3.141.59:test
org.seleniumhq.selenium:selenium-safari-driver:jar:3.141.59:test
Duplicate classes:
META-INF/versions/9/module-info.class

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.097 s
[INFO] Finished at: 2021-05-08T18:37:03+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (default-cli) on project Cross_border_WebTest: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (default-cli) on project Cross_border_WebTest: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed.
at org.apache.maven.plugins.enforcer.EnforceMojo.execute (EnforceMojo.java:237)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

好吧,看了下这个插件没有排除的办法。
搜索了好久,试过了各种不同的办法。如:

     <configuration> 
         <!--<failFast>true</failFast>-->
         <rules>
             <requireJavaVersion>
                 <version>1.6.0</version>
             </requireJavaVersion>
             <banDuplicateClasses>
                 <ignoreClasses>
                         <ignoreClass>org.w3c.dom.*</ignoreClass>   
                          <ignoreClass>com.sun.jna.*</ignoreClass>
                          <ignoreClass>module-info</ignoreClass>
                 </ignoreClasses>
                 <findAllDuplicates>true</findAllDuplicates>
             </banDuplicateClasses>
             <bannedDependencies>
</rules>
 </configuration>

<ignoreClass>module-info</ignoreClass>
还试过:

 <inLibsFilter>!META-INF/**,!META-INF/versions/9/**.class</inLibsFilter>
<ignoredClassPatterns>
  <ignoredClassPattern>
    ^META-INF.versions.9.module-info$
  </ignoredClassPattern>
</ignoredClassPatterns>

结果是他娘的均不好使。

看了篇文章,这个/9/module-info.class 好像是关于jdk9的一些附加内容。我现在用jdk8,不需要用到。
没办法,翻了个强,还别说,这个 佛跳墙是真的很好使。国外的技术网站不错,特别是google的引擎对github类的检索很深入。不像百度,我日,怎么搜索也就那几个博客。

最后看了这边文章解决的。

https://github.com/mojohaus/e...

调整一下,extra-enforcer-rules的版本,哎,我去。。。。JAVA的jar包依赖是真烦人。。

<dependency>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>extra-enforcer-rules</artifactId>
              <version>1.0-beta-4</version>
            </dependency>
          </dependencies>
          <executions>

修改为

              <version>1.0-beta-7</version>

好,编译通过,去do 下一步,尼玛这个破问题搞掉我好几个小时,醉了。

以上是关于META-INF/versions/9/module-info.class 冲突问题解决的主要内容,如果未能解决你的问题,请参考以下文章