我有一些单元测试(虽然它们是 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
重要的是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>
问题是,排除了它抱怨的那些包(我认为问题是这些是 Android 库项目无意中在某些路径列表上结束了两次),它现在抱怨我自己的包。
一位同事错误地建议上面的 <plugin> 部分应该放在 <project><build><pluginManagement> 中。
事实证明 <configuration> 应该直接在 <plugin> 并且应该删除剩余的 <executions> 位,请参阅答案。