如何排除maven-emma插件检测的类?

and*_*sel 2 plugins android emma maven

我有一些单元测试(虽然他们是Android测试,我正在使用Robolectric,所以他们正在运行JVM).他们幸福地跑着,没有报道.

当我尝试覆盖时,我从emma-maven收到此错误:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:emma-maven-plugin:1.0-alpha-3:instrument (default-cli) on project android: Execution default-cli of goal org.codehaus.mojo:emma-maven-plugin:1.0-alpha-3:instrument failed: class [com.larvalabs.svgandroid.ParserHelper] appears to be instrumented already
Run Code Online (Sandbox Code Playgroud)

重要的是class .... appears to be instrumented already.

找到合适的文档非常困难,但这就是我从各种来源拼凑出的配置:

<plugin>
    <!-- This doesn't work, see below for a working configuration -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>emma-maven-plugin</artifactId>
    <version>1.0-alpha-3</version>
    <inherited>true</inherited>                          
    <executions>
            <execution>
                    <phase>process-classes</phase>                               
                    <configuration>
                            <filters>
                                    <filter>-com.viewpagerindicator.*</filter>
                                    <filter>-com.actionbarsherlock.*</filter>
                                    <filter>-com.larvalabs.svgandroid.*</filter>
                            </filters>
                    </configuration>
                    <goals> 
                            <goal>instrument</goal>
                    </goals>
            </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

麻烦的是,排除了那些抱怨的软件包(我认为问题是这些是Android库项目无意中在某些路径列表中无意中结束了两次),现在它正在抱怨我自己的软件包.


一位同事错误地建议上面的<plugin>部分应该进入<project> <build> <pluginManagement>.

事实证明<configuration>应该直接在<plugin>中,并且应该删除剩余的<executions>位,请参阅答案.

and*_*sel 5

我找到了一个解决方案 - 令人尴尬的简单.

忘记插件管理的东西:只有通过使它忽略/ this/pom的过滤器才能"工作",但是将它们应用到任何子poms:http://maven.apache.org/pom.html#Plugin_Management

只需将配置元素移出执行块,然后删除执行块.http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Generic_Configuration

使用插件元素中的配置部分,使用'mvn -X emma:emma'运行时会显示列出的过滤器.由于每个排除行都改变了我看到的错误,我推断它是排除的.(我收集到包括,你添加带+前缀的过滤器来覆盖前面的部分 - 前缀.)

<project>
 <build>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>emma-maven-plugin</artifactId>
    <version>1.0-alpha-3</version>
    <!-- inherited>true</inherited -->
    <configuration>
            <filters>
                    <filter>-com.viewpagerindicator.*</filter>
                    <filter>-com.actionbarsherlock.*</filter>
                    <filter>-com.larvalabs.svgandroid.*</filter>
            </filters>
            <!-- verbose>true</verbose -->
   </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

到目前为止问题的隐含Android部分(这实际上使得过滤对我来说没有问题),因为Android需要一个单独的APK来保存测试并运行主应用程序APK,你根本就不需要运行Android集成测试同一个项目:android插件希望你从一个单独的项目中进行集成测试APK - 通常是同一个父pom文件下的兄弟.在android插件页面上隐藏了一个zip中的示例/示例项目 - http://code.google.com/p/maven-android-plugin/wiki/Samples - 您应在其中搜索"coverage"并更改它至:

<coverage>true</coverage>
Run Code Online (Sandbox Code Playgroud)

配置 - 一些样本有它,但注释掉了.我分心了,所以不记得是否有效,但显然应该这样做.

由于我们不想将目录级别插入到项目的现有源代码控制中,因此我们创建了名为"parent"和"integration"的目录作为应用程序pom.xml的对等项,使用"parent"来保存父pom,以及集成'用于集成测试,本节告诉app/pom.xml使用app/parent/pom.xml:

<project>
    <parent>
            <groupId>our.group.id</groupId>
            <artifactId>base</artifactId>
            <relativePath>parent</relativePath>
            <version>3.9.0</version>
    </parent>
Run Code Online (Sandbox Code Playgroud)

这在app/integration/pom.xml中:

<project>
  <parent>
    <groupId>our.group.id</groupId>
    <artifactId>base</artifactId>
    <relativePath>../parent</relativePath>
    <version>3.9.0</version>
  </parent>
Run Code Online (Sandbox Code Playgroud)