我有一个打包为耳朵的项目。在过去一个月左右的时间里,系统测试已被禁用。我们重新打开它们,并一直在修复失败的测试和构建脚本的问题。我还没能破解最新的问题:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-test) on project systemTest: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test: org/junit/runner/notification/RunListener
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-surefire-plugin:2.14.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/tomcat/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.14.1/maven-surefire-plugin-2.14.1.jar
[ERROR] urls[1] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-junit47/2.14.1/surefire-junit47-2.14.1.jar
[ERROR] urls[2] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-junit48/2.14.1/common-junit48-2.14.1.jar
[ERROR] urls[3] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-junit4/2.14.1/common-junit4-2.14.1.jar
[ERROR] urls[4] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-junit3/2.14.1/common-junit3-2.14.1.jar
[ERROR] urls[5] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-grouper/2.14.1/surefire-grouper-2.14.1.jar
[ERROR] urls[6] = file:/home/tomcat/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
[ERROR] urls[7] = file:/home/tomcat/.m2/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
[ERROR] urls[8] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-java5/2.14.1/common-java5-2.14.1.jar
[ERROR] urls[9] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.14.1/maven-surefire-common-2.14.1.jar
[ERROR] urls[10] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-booter/2.14.1/surefire-booter-2.14.1.jar
[ERROR] urls[11] = file:/home/tomcat/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
[ERROR] urls[12] = file:/home/tomcat/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
[ERROR] urls[13] = file:/home/tomcat/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
[ERROR] urls[14] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-api/2.14.1/surefire-api-2.14.1.jar
[ERROR] urls[15] = file:/home/tomcat/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: org.junit.runner.notification.RunListener
[ERROR] -> [Help 1]
我不明白如何找不到 org/junit/runner/notification/RunListener 。整个项目是使用 maven 构建的,并且包含 junit
作为测试依赖项。
据我们所知,除了构建服务器之外,在任何地方都可以进行完整的构建。第二个有趣的点是,在构建服务器上,当不包含系统测试时,一切都会构建得很好,而系统测试在单独运行时也能正常工作。仅当构建完整项目(包括系统测试)时,才会出现此问题。
这是用于系统测试的 pom.xml
的相关部分
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>com/crowncastle/test/*Test.class</include>
<include>com/crowncastle/test/suite/*TestSuite.class</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}${file.separator}..${file.separator}ear${file.separator}src${file.separator}main${file.separator}application${file.separator}APP-INF${file.separator}classes</additionalClasspathElement>
<additionalClasspathElement>${basedir}${file.separator}..${file.separator}ff${file.separator}src${file.separator}main${file.separator}resources</additionalClasspathElement>
<additionalClasspathElement>${basedir}${file.separator}..${file.separator}ff${file.separator}target${file.separator}classes</additionalClasspathElement>
<additionalClasspathElement>${basedir}${file.separator}..${file.separator}ff${file.separator}target${file.separator}test-classes</additionalClasspathElement>
</additionalClasspathElements>
<forkMode>always</forkMode>
<argLine>-Xmx1024m -XX:MaxPermSize=512m</argLine>
<runOrder>alphabetical</runOrder>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<forkedProcessTimeoutInSeconds>900</forkedProcessTimeoutInSeconds>
</configuration>
</plugin>
更新
我认为也许有旧版本的 junit 可能会导致问题,所以我运行了 mvn dependency:analyze 和 mvn dependency:tree > 但唯一提到的 junit
是 junit 4.10
,这是合适的版本。
更新 我们能够在测试构建服务器上复制该问题。我之前没有提到开发人员工作站运行 Windows 8,构建服务器是 Linux。所以这可能是 Windows 与 Linux 的问题,但我不明白是什么。
最佳答案
该问题是两个因素综合作用的结果:
首先,存在传递依赖问题(即 hamcrest-core 1.1 -> jmock 1.1.0 -> JUnit 3.8.1 的问题),其中(在 Maven 的依赖树中)旧的 JUnit “更接近”systemTest模块(继承了版本依赖),并且 JUnit 的修订版 3.8.1 不包含 org.junit.runner.notification.RunListener。
其次,对 <version>
的解释存在困惑。由 maven 标记--具有 <version>4.10</version>
表示 junit 的软要求,而不是硬要求(可能用 <version>[4.10]</version>
表示)
(另请参阅 Maven Dependency Mediation ))
后者导致 Maven 接受“最接近”令人满意的 JUnit 依赖项(在本例中为 3.8)而不是预期值,从而引发错误。将 pom 更改为 [N.mm] 'hard' 语法可以解决此问题。
关于java - 执行 org.apache.maven.plugins :maven-surefire-plugin:2. 14.1:test: org/junit/runner/notification/RunListener 时缺少必需的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16420935/