2

我有一个打包为耳朵的项目。在过去一个月左右的时间里,系统测试已被禁用。我们重新打开它们,并一直在修复失败的测试和构建脚本的问题。我一直无法破解最新的问题:

[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:analyzemvn dependency:tree但唯一提到的junitjunit 4.10,这是合适的版本。

更新 我们能够在我们的测试构建服务器上复制问题。之前我没有提到开发者工作站运行windows 8,构建服务器是linux。所以它可能是一个 windows 与 linux 的问题,但我不明白是什么。

4

2 回答 2

2

这个问题是两个因素的结合:

首先,存在传递依赖问题(即 hamcrest-core 1.1 -> jmock 1.1.0 -> JUnit 3.8.1 的问题),其中(在 Maven 的依赖树中)旧的 JUnit 更接近 systemTest 模块(其中继承了版本依赖),而 JUnit 的 3.8.1 版本不包含 org.junit.runner.notification.RunListener。

其次,maven 对<version>标签的解释存在混淆——<version>4.10</version>表示对 junit 的要求,而不是硬要求(可能用<version>[4.10]</version> (另见Maven Dependency Mediation)表示)

后者导致 maven 接受“最接近”的令人满意的 JUnit 依赖项(在本例中为 3.8)而不是预期值,从而导致错误。将 pom 更改为 [N.mm] 'hard' 语法可以解决此问题。

于 2013-09-06T14:34:03.797 回答
2

我今天在重建开发环境时遇到了类似的问题。少数 jar 下载不正确。我能够通过从我的 Maven 存储库中删除问题文件夹来继续。这迫使 Maven 再次下载它们,然后它们就可以正常工作了。

在这种情况下,我删除了:

{local_repo}\org\apache\maven\plugins\maven-surefire-plugin

于 2013-09-05T16:07:36.767 回答