java 执行 org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test: org/junit/runner/notification/RunListener 时缺少必需的类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16420935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test: org/junit/runner/notification/RunListener
提问by pgreen2
I have a project which is packaged as an ear. For the past month or so system tests have been disabled. We turned them back on and have been fixing problems with failed tests and the build script. I have not been able to crack the latest problem:
我有一个打包成耳朵的项目。在过去一个月左右的时间里,系统测试已被禁用。我们重新打开它们,并一直在修复失败的测试和构建脚本的问题。我一直无法破解最新的问题:
[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]
I can't figure out how org/junit/runner/notification/RunListener can't be found. The whole project is build with maven and junit
is included as a test dependency.
我不知道如何找不到 org/junit/runner/notification/RunListener。整个项目是用 maven 构建的,并junit
作为测试依赖项包含在内。
As far as we can tell, doing a full build works everywhere except on the build server. Second interesting point, on the build server, everything builds fine when system tests aren't included and system tests work fine when run by themselves. The problem only happens when the full project is built including the system tests.
据我们所知,除了在构建服务器上,进行完整构建在任何地方都有效。第二个有趣的点是,在构建服务器上,当不包含系统测试时,一切都构建得很好,而系统测试在自己运行时也能正常工作。只有在构建包括系统测试在内的完整项目时才会出现问题。
This is the relevant portion of the pom.xml
for the system tests
这是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>
UpdateI thought perhaps there was an older version of junit
hanging around that could be causing problems, so I ran mvn dependency:analyze
and mvn dependency:tree
but the only mention of junit
is junit 4.10
, which is the appropriate version.
更新我想也许有一个旧版本的junit
挂起可能会导致问题,所以我跑了mvn dependency:analyze
,mvn dependency:tree
但唯一提到的junit
是junit 4.10
,这是合适的版本。
UpdateWe were able to duplicate the problem on our test build server. I didn't mention before that the developer workstations run windows 8 and the build server is linux. So it could be a windows vs linux problem, but I don't see what.
更新我们能够在我们的测试构建服务器上复制问题。我之前没有提到开发人员工作站运行 Windows 8,构建服务器是 linux。所以这可能是 windows vs linux 的问题,但我不明白是什么。
回答by klazarus
The issue was a combination of two factors:
这个问题是两个因素的结合:
First, there was a transitive dependency problem (namely that of hamcrest-core 1.1 -> jmock 1.1.0 -> JUnit 3.8.1) where (in Maven's dependency-tree) the older JUnit was 'closer' to the systemTest module (which was inheriting the version dependency), and revision 3.8.1 of JUnit doesn't have contain org.junit.runner.notification.RunListener.
首先,存在一个传递依赖问题(即 hamcrest-core 1.1 -> jmock 1.1.0 -> JUnit 3.8.1),其中(在 Maven 的依赖树中)旧的 JUnit 与 systemTest 模块“更接近”(它继承了版本依赖),并且 JUnit 的 3.8.1 修订版不包含 org.junit.runner.notification.RunListener。
Second, there was confusion over the interpretation of the <version>
tag by maven-- having <version>4.10</version>
indicates a softrequirement for junit, rather than a hard requirement (which might be indicated with <version>[4.10]</version>
(see also Maven Dependency Mediation))
其次,<version>
maven对标签的解释存在混淆——<version>4.10</version>
表示对 junit的软需求,而不是硬需求(这可能用<version>[4.10]</version>
(另见Maven Dependency Mediation)表示)
The latter led maven to accept the 'closest' satisfactory JUnit dependency (which in this case was 3.8) rather than the expected value, thereby giving rise to the error. Altering the pom to the [N.mm] 'hard' syntax resolves this problem.
后者导致 maven 接受“最接近”令人满意的 JUnit 依赖项(在本例中为 3.8)而不是预期值,从而导致错误。将 pom 更改为 [N.mm] 'hard' 语法可解决此问题。
回答by Darin
I have been having a similar issue today while rebuilding dev environment. A handful of jars were downloaded incorrectly. I was able to continue by spot-deleting the problem folders from my maven repository. This forced maven to download them again, and then they worked without problem.
我今天在重建开发环境时遇到了类似的问题。少数 jars 下载不正确。我能够通过从我的 Maven 存储库中点删除问题文件夹来继续。这迫使 maven 再次下载它们,然后它们就可以正常工作了。
In this case I removed:
在这种情况下,我删除了:
{local_repo}\org\apache\maven\plugins\maven-surefire-plugin
{local_repo}\org\apache\maven\plugins\maven-surefire-plugin