maven surefire排除:它是否有车?

时间:2014-03-19 07:01:11

标签: maven classnotfoundexception surefire

注意:我已经为此http://jira.codehaus.org/browse/MNG-5603提交了官方JIRA,因为我非常确定它是maven中的一个错误。这个帖子的答案我将在这两个地方评估和更新,因为我非常确定在复杂的代码库上做排除过滤器时,其他人会遇到这个问题。

我的完整pom文件在这里供参考:https://gist.github.com/jayunit100/9644221(这是我在源代码中玩的hadoop版本。)

我发现了一些非常奇怪的行为:

mvn test

使用以下排除过滤器"排除"标记:

<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <systemPropertyVariables>
        <startKdc>${startKdc}</startKdc>
        <kdc.resource.dir>${kdc.resource.dir}</kdc.resource.dir>
      </systemPropertyVariables>
      <properties>
        <property>
          <name>listener</name>
          <value>org.apache.hadoop.test.TimedOutTestsListener</value>
        </property>
      </properties>
      <excludes>
      <exclude>asbdfoin</exclude>
  </excludes>
    </configuration>

导致如下例外:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.16:test 
(default-test) on project hadoop-common: Execution default-test of goal 
org.apache.maven.plugins:maven-surefire-plugin:2.16:test failed: 
java.lang.NoClassDefFoundError: EmptyRequestProto; nested exception is 
java.lang.NoClassDefFoundError: EmptyRequestProto -> [Help 1]

换句话说:当排除过滤器根本不匹配任何内容时,排除过滤器可能会产生NoClassDefFoundError消息。

我的问题:maven surefire排除过滤器怎么会导致ClassNotFound错误显示?如果有的话,我希望它减少加载类的尝试量,而不是增加它们。

仅供参考,其中有一些颜色:该类本身就是一个内部类:

public static final class EmptyRequestProto extends com.google.protobuf.GeneratedMessage

我见过https://jira.codehaus.org/browse/SUREFIRE-988,可能还有相关内容,但事实上我的排除了#34; filter不匹配代码库中的任何类,它可能是不同的。

1 个答案:

答案 0 :(得分:0)

这是我的万无一失的配置。我已经包含了一个绝对不匹配的排除。它对我有用。我无法重现你的异常。也许你在你的pom中错误配置了它。

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.16</version>
     <configuration>
        <excludes>
            <exclude>abcdefghijk</exclude>
        </excludes>
            <forkMode>once</forkMode>
     </configuration>
</plugin>