2012-07-06 37 views
6

我需要使用surefire v2.12,但每次运行该版本时都会附上堆栈跟踪信息。如果我运行v2.10,我不会收到错误消息。我需要这个版本,所以我可以用@Category注释我的测试类,并将它们标记为UnitTests或IntegrationTests。 这里是我的命令:MVN测试-Dsurefire.version = 2.12 -X保证插件在测试阶段在maven中出现异常

 
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project PROJECT: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null: ExceptionInInitializerError: Unexpected ClassNotFoundException looking up class 'org.apache.maven.cli.MavenCli' -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project ASPEN: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 
    Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
    ... 19 more 
    Caused by: org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:197) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeGetter(ReflectionUtils.java:69) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.getSuites(ProviderFactory.java:148) 
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.getSuitesIterator(ForkStarter.java:317) 
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkPerTestSet(ForkStarter.java:149) 
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:118) 
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:199) 
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAllProviders(AbstractSurefireMojo.java:176) 
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:135) 
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:98) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
    ... 20 more 
    Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
    ... 30 more 
    Caused by: java.lang.ExceptionInInitializerError 
    ... 2 more 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:169) 
    at org.junit.runner.Description.getTestClass(Description.java:207) 
    at org.apache.maven.surefire.common.junit48.FilterFactory$GroupMatcherCategoryFilter.shouldRun(FilterFactory.java:207) 
    at org.apache.maven.surefire.junitcore.JUnitCoreProvider.getSuitesAsList(JUnitCoreProvider.java:169) 
    at org.apache.maven.surefire.junitcore.JUnitCoreProvider.getSuites(JUnitCoreProvider.java:102) 
    ... 35 more 
    Caused by: java.lang.RuntimeException: Unexpected ClassNotFoundException looking up class 'org.apache.maven.cli.MavenCli' 
    ... 12 more 

    (deleted lines here) 

我的pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<parent> 
    <artifactId>sample</artifactId> 
    <groupId>sample</groupId> 
    <version>1.0</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 
<artifactId>webapp</artifactId> 
<packaging>war</packaging> 
<dependencies> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>${org.slf4j-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>${org.slf4j-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-all</artifactId> 
     <version>1.9.0</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
    </dependency> 
</dependencies> 
<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>findbugs-maven-plugin</artifactId> 
      <version>2.5.1</version> 
     </plugin> 
    </plugins> 
</reporting> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <dependencies> 
       <dependency> 
        <groupId>org.apache.maven.surefire</groupId> 
        <artifactId>surefire-junit47</artifactId> 
        <version>${surefire.version}</version> 
        <scope>test</scope> 
       </dependency> 
      </dependencies> 
      <configuration> 
       <groups>com.webapp.api.annotation.type.${group.include}</groups> 
       <excludedGroups>com.webapp.api.annotation.type.${group.exclude}</excludedGroups> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
</project> 

另外,我是能够做到这一点在不同的项目中,我从成立废料。但在这种情况下,你可以看到我正在覆盖surefire插件版本。

任何想法?

感谢

+0

您使用的是哪个版本的maven? – gkamal 2012-07-07 06:36:51

+0

如果你有集成测试,maven-surefire-plugin是错误的方法。对于集成测试,请使用maven-failsafe插件。 – khmarbaise 2012-07-07 13:39:37

+0

@gkamal我正在使用maven 3.0.4 – bclarance 2012-07-07 15:01:17

回答

1

为什么不把版本到这个POM,导致这个POM是由你掌控和谁比谁永远会使用你的项目将是惊讶,这是行不通的,因为他错过了给属性在命令行上。顺便说一句:你是否通过mvn -X -Dsurefire.version = 2.12等来检查输出。我想你会得到相同的错误信息。

我已复查,如果你以这种方式定义版本的项目是不正确的了,如果有人错过的命令行选项(-D ......),你会得到这样的事情:

INFO] Scanning for projects... 
[ERROR] The build could not read 1 project -> [Help 1] 
[ERROR] 
[ERROR] The project com.soebes.katas:code:1.0-SNAPSHOT (/home/katas/pom.xml) has 1 error 
[ERROR]  'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin must be a valid version but is '${surefire.version}'. @ line 36, column 20 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[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/ProjectBuildingException 

换句话说,通过命令行上的选项来定义插件版本(或其依赖关系)是一个非常糟糕的主意。 我只是推荐你在你的pom中定义所有你需要的版本,并通过surefire和/或故障安全插件正确使用单元和集成测试。这将解决你的问题。

+0

我完全同意,并且最终会更新父pom。我的问题是,父pom有许多其他家属,所以我需要验证它是否正在工作,然后才能够永久应用此更改/升级。是的,我用-X选项运行它,但没有看到这对我有什么帮助。如果你知道要寻找什么,请告知。 – bclarance 2012-07-07 16:27:30

+0

只需将版本号放在你的pom中并以此方式进行测试即可。此外,在命令行上使用插件和/或依赖项的版本不起作用。这将需要50秒来改变这个pom并且用你给出的版本进行测试。你可以在pom中评论为什么你决定使用不同的maven-surefire-pugin版本而不是继承版本。 – khmarbaise 2012-07-07 16:31:44

+0

用版本更改了项目pom并仍然出现异常; mvn clean test -e -X。下面是一些输出来验证更改是否生效:[DEBUG] org.apache.maven.surefire:surefire-api:jar:2.12:编译(选择编译)任何其他想法? – bclarance 2012-07-07 16:46:28

相关问题