Running jacoco check goal with maven 3.5

瘦欲@ 提交于 2021-02-11 10:20:06

问题


My jacoco plugin configuration in a pom likes below

<plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.5.201505241946</version>
              <executions>
                <execution>
                  <id>pre-unit-test</id>
                  <goals>
                      <goal>prepare-agent</goal>
                  </goals>
                  <configuration>
                    <destFile>${jacoco.ut.execution.data.file}</destFile>
                  </configuration>
                </execution>
                <execution>
                  <id>merge-execs</id>
                  <phase>pre-site</phase>
                  <inherited>false</inherited>
                  <goals>
                      <goal>merge</goal>
                  </goals>
                  <configuration>
                   <fileSets>
                     <fileSet>
                       <directory>${basedir}</directory>
                       <includes>
                         <include>**/target/*.exec</include>
                       </includes>
                     </fileSet>
                   </fileSets>
                    <destFile>${jacoco.ut.merged.exec}</destFile>
                  </configuration>
                </execution>
                  <execution>
                      <id>jacoco-check</id>
                      <phase>verify</phase>
                      <goals>
                          <goal>check</goal>
                      </goals>
                      <configuration>
                          <rules>
                              <rule>
                                  <element>BUNDLE</element>
                                  <limits>
                                      <limit>
                                          <counter>LINE</counter>
                                          <value>COVEREDRATIO</value>
                                          <minimum>0.80</minimum>
                                      </limit>
                                  </limits>
                              </rule>
                          </rules>
                          <dataFile>${jacoco.ut.merged.exec}</dataFile>
                      </configuration>
                  </execution>
             </executions>
         </plugin>

But when I am running mvn jacoco:check it is failing with the below error

[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:check (default-cli) on project main: The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:check are missing or invalid -> [Help 1]

Can someone let me know what is going wrong?


回答1:


Behavior that you observe is not specific to jacoco-maven-plugin, it is how Maven works - see https://maven.apache.org/guides/mini/guide-default-execution-ids.html

mvn jacoco:check

uses execution id default-cli, while your pom.xml defines configuration in execution with id jacoco-check bound to phase verify.

So either use this phase:

mvn verify

Or provide configuration outside of executions block (i.e. in <plugin><configuration>) so that it will be inherited in all executions.

Or explicitly specify execution id jacoco-check:

mvn jacoco:check@jacoco-check


来源:https://stackoverflow.com/questions/57340266/running-jacoco-check-goal-with-maven-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!