执行org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions:org.junit.rules.TestRule时缺少必需的类

时间:2019-02-20 11:22:22

标签: java junit maven-3 maven-plugin assertj

将我的应用程序从JDK8迁移到JDK11时遇到此问题。

[ERROR] Failed to execute goal org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions (default) on project mws-inbound: Execution default of goal org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions failed: A required class was missing while executing org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions: org.junit.rules.TestRule
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.assertj:assertj-assertions-generator-maven-plugin:2.1.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/admin/.m2/repository/org/assertj/assertj-assertions-generator-maven-plugin/2.1.0/assertj-assertions-generator-maven-plugin-2.1.0.jar
[ERROR] urls[1] = file:/C:/Users/admin/.m2/repository/org/assertj/assertj-assertions-generator/2.1.0/assertj-assertions-generator-2.1.0.jar
[ERROR] urls[2] = file:/C:/Users/admin/.m2/repository/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar
[ERROR] urls[3] = file:/C:/Users/admin/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
[ERROR] urls[4] = file:/C:/Users/admin/.m2/repository/com/google/guava/guava/20.0/guava-20.0.jar
[ERROR] urls[5] = file:/C:/Users/admin/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar
[ERROR] urls[6] = file:/C:/Users/admin/.m2/repository/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar
[ERROR] urls[7] = file:/C:/Users/admin/.m2/repository/org/assertj/assertj-core/2.9.1/assertj-core-2.9.1.jar
[ERROR] urls[8] = file:/C:/Users/admin/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
[ERROR] urls[9] = file:/C:/Users/admin/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar
[ERROR] urls[10] = file:/C:/Users/admin/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[11] = file:/C:/Users/admin/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
[ERROR] urls[12] = file:/C:/Users/admin/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:171)
    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 jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: org.apache.maven.plugin.PluginContainerException: A required class was missing while executing org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions: org.junit.rules.TestRule

我的配置:

<plugin>
     <groupId>org.assertj</groupId>
     <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
     <configuration>
         <packages>
            <param>com.etech.zws.domain.persistent</param>
            <param>com.etech.zws.inbound.model.dto.ping</param>         
         </packages>
      </configuration>
      <executions>
          <execution>
             <goals>
                 <goal>generate-assertions</goal>
             </goals>
          </execution>
      </executions>
</plugin>

插件似乎无法找到junit jar。 我的junit版本:<junit.version>4.12</junit.version>

这是基本配置。 我以前没有这个问题。

任何帮助将不胜感激。

非常感谢。

1 个答案:

答案 0 :(得分:0)

有趣的是:

  

由以下原因引起:org.apache.maven.plugin.PluginContainerException:A   执行时缺少所需的类   org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions:   org.junit.rules.TestRule

Maven插件可能需要依赖项,尤其是依赖项的特定版本。
对于可用于多个测试运行器/框架库(至少是JUnit和TestNG)的AssertJ来说,这很有意义。因此,是的,您可能需要在插件声明中添加junit依赖关系,以指定一个提供所需功能的版本:

<plugin>
     <groupId>org.assertj</groupId>
     <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
    <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
      </dependency>
     </dependencies>
     <configuration>
         <packages>
            <param>com.etech.zws.domain.persistent</param>
            <param>com.etech.zws.inbound.model.dto.ping</param>         
         </packages>
      </configuration>
      <executions>
          <execution>
             <goals>
                 <goal>generate-assertions</goal>
             </goals>
          </execution>
      </executions>
</plugin>