我正在尝试使用以下命令在父pom.xml文件上进行Maven全新安装-

mvn clean install -Dmaven.test.skip=true -Dmaven.it.skip=true -DcoberturaHaltOnError=false


但是无论如何,每次都会出现以下错误-

[INFO] --- cobertura-maven-plugin:2.5.2:check (default) @ tac-core ---
[INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 237 classes.

[ERROR] com.somehost.core.exception.LockedException failed check. Line coverage rate of 0.0% is below 80.0%
com.somehost.core.dao.impl.DAOReadOnlyImpl failed check. Branch coverage rate of 0.0% is below 90.0%
com.somehost.core.dao.impl.DAOReadOnlyImpl failed check. Line coverage rate of 0.0% is below 80.0%
com.somehost.core.service.Service failed check. Branch coverage rate of 0.0% is below 90.0%
com.somehost.core.service.Service failed check. Line coverage rate of 0.0% is below 80.0%
com.somehost.core.msg.client.StoreResponse failed check. Branch coverage rate of 0.0% is below 90.0%

// followed by other errors


我不确定如何以使子模块不会失败的方式跳过父pom.xml文件中的cobertura测试。从上述错误看来,我的核心模块出现了故障(请参见下面的父pom.xml文件)

以下是我的父pom.xml文件-

<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">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.somehost</groupId>
   <artifactId>tac-parent</artifactId>
   <version>MAIN</version>
   <packaging>pom</packaging>
   <name>Host-TAC</name>

   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <release.version>MAIN</release.version>
      <cobertura.version>1.9.4</cobertura.version>
      <maven.test.skip>false</maven.test.skip>
      <maven.it.skip>false</maven.it.skip>
      <coberturaHaltOnError>true</coberturaHaltOnError>
   </properties>

   <modules>
      <module>core</module>
      <module>webapp</module>
      <module>client</module>
      <module>panner</module>
   </modules>

   <pluginRepositories>
      <pluginRepository>
         <id>caucho</id>
         <name>Caucho</name>
         <url>http://caucho.com/m2-snapshot</url>
      </pluginRepository>
   </pluginRepositories>

   <repositories>
      <repository>
         <id>caucho.maven-repo</id>
         <name>Caucho Repository</name>
         <url>http://caucho.com/m2-snapshot</url>
      </repository>
      <repository>
         <id>java.net-Public</id>
         <name>Maven Java Net Snapshots and Releases</name>
         <url>https://maven.java.net/content/groups/public/</url>
      </repository>
   </repositories>

   <dependencies>
      <dependency>
         <groupId>com.caucho</groupId>
         <artifactId>resin</artifactId>
         <version>4.0-SNAPSHOT</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.caucho</groupId>
         <artifactId>resin-javaee</artifactId>
         <version>4.0-SNAPSHOT</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>javax.validation</groupId>
         <artifactId>validation-api</artifactId>
         <version>1.0.0.GA</version>
         <scope>provided</scope>
      </dependency>

      <dependency>
         <groupId>javax.xml.bind</groupId>
         <artifactId>jaxb-api</artifactId>
         <version>2.2.4</version>
      </dependency>

      <dependency>
         <groupId>com.sun.xml.bind</groupId>
         <artifactId>jaxb-impl</artifactId>
         <version>2.2.4-1</version>
      </dependency>

      <dependency>
         <groupId>com.host</groupId>
         <artifactId>trustedsource</artifactId>
         <version>2.2.0.2</version>
      </dependency>

      <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>12.0</version>
      </dependency>

      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>1.6.4</version>
      </dependency>
      <!--
             <dependency>
               <groupId>org.slf4j</groupId>
               <artifactId>slf4j-jdk14</artifactId>
               <version>1.6.4</version>
            </dependency>
      -->
      <dependency>
         <groupId>ch.qos.logback</groupId>
         <artifactId>logback-classic</artifactId>
         <version>1.0.0</version>
      </dependency>
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>jul-to-slf4j</artifactId>
         <version>1.6.4</version>
      </dependency>

      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.3</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-simple</artifactId>
         <version>1.6.4</version>
         <scope>test</scope>
      </dependency>

   </dependencies>

   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-core</artifactId>
            <version>${project.version}</version>
         </dependency>

         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-client</artifactId>
            <version>${project.version}</version>
         </dependency>

         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-scanner</artifactId>
            <version>${project.version}</version>
         </dependency>

         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-webapp</artifactId>
            <version>${project.version}</version>
         </dependency>
      </dependencies>
   </dependencyManagement>


 <profiles>
      <profile>
         <id>cobertura-instrument</id>
         <activation>
            <property>
               <name>cobertura-build</name>
            </property>
         </activation>
         <modules>
            <module>tac-cobertura</module>
         </modules>
         <build>
            <plugins>
               <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>cobertura-maven-plugin</artifactId>
                  <version>2.5.2</version>
                   <configuration>
                           <check>
                             <haltOnFailure>${coberturaHaltOnerror}</haltOnFailure>
                             <totalLineRate>90</totalLineRate>
                             <totalBranchRate>90</totalBranchRate>
                           </check>
                           <formats>
                             <format>html</format>
                           </formats>
                   </configuration>
                  <executions>
                     <execution>
                        <id>instrument-code</id>
                        <phase>process-classes</phase>
                        <goals>
                           <goal>instrument</goal>
                        </goals>
                        <configuration>
                           <attach>true</attach>
                        </configuration>
                     </execution>
                  </executions>
               </plugin>
               <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-source-plugin</artifactId>
                  <version>2.2.1</version>
                  <executions>
                     <execution>
                        <id>attach-sources</id>
                        <goals>
                           <goal>jar</goal>
                        </goals>
                     </execution>
                  </executions>
                  <inherited>true</inherited>
               </plugin>
            </plugins>
         </build>
         <dependencies>
            <dependency>
               <groupId>net.sourceforge.cobertura</groupId>
             <artifactId>cobertura-runtime</artifactId>
               <version>${cobertura.version}</version>
               <scope>provided</scope>
               <type>pom</type>
            </dependency>
         </dependencies>
      </profile>
   </profiles>


   <build>
      <finalName>tac-${project.version}-r${buildNumber}</finalName>
      <pluginManagement>
         <plugins>
            <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>buildnumber-maven-plugin</artifactId>
               <version>1.0</version>
            </plugin>
            <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>cobertura-maven-plugin</artifactId>
               <version>2.5.2</version>
            </plugin>
         </plugins>
      </pluginManagement>

      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
               <execution>
                  <phase>validate</phase>
                  <goals>
                     <goal>create</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <useLastCommittedRevision>true</useLastCommittedRevision>
               <scmDirectory>${project.parent.basedir}</scmDirectory>
               <doCheck>false</doCheck>
               <doUpdate>false</doUpdate>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.6</version>
            <executions>
               <execution>
                  <id>bundle-manifest</id>
                  <phase>process-resources</phase>
                  <goals>
                     <goal>manifest</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <supportedProjectTypes>
                  <supportedProjectType>jar</supportedProjectType>
                  <supportedProjectType>bundle</supportedProjectType>
                  <supportedProjectType>war</supportedProjectType>
               </supportedProjectTypes>
               <instructions>
                  <Build-version>${buildNumber}</Build-version>
               </instructions>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
               <instrumentation>
                  <includes>
                     <include>com/somehost/**/*.class</include>
                  </includes>
                  <!--
                  <ignores>
                     <ignore>com.example.boringcode.*</ignore>
                  </ignores>
                  -->
                  <!--
                  <excludes>
                     <exclude>com/example/dullcode/**/*.class</exclude>
                     <exclude>com/example/**/*Test.class</exclude>
                  </excludes>
                  -->
               </instrumentation>
               <check>
                  <branchRate>85</branchRate>
                  <lineRate>85</lineRate>
                  <haltOnFailure>true</haltOnFailure>
                  <totalBranchRate>85</totalBranchRate>
                  <totalLineRate>85</totalLineRate>
                  <packageLineRate>85</packageLineRate>
                  <packageBranchRate>85</packageBranchRate>
                  <regexes>
                     <regex>
                        <pattern>com.somehost.*</pattern>
                        <branchRate>90</branchRate>
                        <lineRate>80</lineRate>
                     </regex>
                  </regexes>
               </check>
            </configuration>
            <executions>
               <execution>
                  <goals>
                     <goal>clean</goal>
                     <goal>check</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

   <reporting>
      <plugins>
         <plugin>
            <groupId>org.codehause.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
               <formats>
                  <format>html</format>
                  <format>xml</format>
               </formats>
            </configuration>
         </plugin>
      </plugins>
   </reporting>
</project>


更新代码:

以下是我更新的父pom.xml文件,但仍然出现相同的错误-

<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">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.somehost</groupId>
   <artifactId>tac-parent</artifactId>
   <version>MAIN</version>
   <packaging>pom</packaging>
   <name>Host-TAC</name>

   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <release.version>MAIN</release.version>
      <cobertura.version>1.9.4</cobertura.version>
      <maven.test.skip>false</maven.test.skip>
      <maven.it.skip>false</maven.it.skip>
      <coberturaHaltOnError>true</coberturaHaltOnError>
   </properties>

   <modules>
      <module>core</module>
      <module>webapp</module>
      <module>client</module>
      <module>panner</module>
   </modules>

   <pluginRepositories>
      <pluginRepository>
         <id>caucho</id>
         <name>Caucho</name>
         <url>http://caucho.com/m2-snapshot</url>
      </pluginRepository>
   </pluginRepositories>

   <repositories>
      <repository>
         <id>caucho.maven-repo</id>
         <name>Caucho Repository</name>
         <url>http://caucho.com/m2-snapshot</url>
      </repository>
      <repository>
         <id>java.net-Public</id>
         <name>Maven Java Net Snapshots and Releases</name>
         <url>https://maven.java.net/content/groups/public/</url>
      </repository>
   </repositories>

   <dependencies>
      <dependency>
         <groupId>com.caucho</groupId>
         <artifactId>resin</artifactId>
         <version>4.0-SNAPSHOT</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.caucho</groupId>
         <artifactId>resin-javaee</artifactId>
         <version>4.0-SNAPSHOT</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>javax.validation</groupId>
         <artifactId>validation-api</artifactId>
         <version>1.0.0.GA</version>
         <scope>provided</scope>
      </dependency>

      <dependency>
         <groupId>javax.xml.bind</groupId>
         <artifactId>jaxb-api</artifactId>
         <version>2.2.4</version>
      </dependency>

      <dependency>
         <groupId>com.sun.xml.bind</groupId>
         <artifactId>jaxb-impl</artifactId>
         <version>2.2.4-1</version>
      </dependency>

      <dependency>
         <groupId>com.host</groupId>
         <artifactId>trustedsource</artifactId>
         <version>2.2.0.2</version>
      </dependency>

      <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>12.0</version>
      </dependency>

      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>1.6.4</version>
      </dependency>
      <!--
             <dependency>
               <groupId>org.slf4j</groupId>
               <artifactId>slf4j-jdk14</artifactId>
               <version>1.6.4</version>
            </dependency>
      -->
      <dependency>
         <groupId>ch.qos.logback</groupId>
         <artifactId>logback-classic</artifactId>
         <version>1.0.0</version>
      </dependency>
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>jul-to-slf4j</artifactId>
         <version>1.6.4</version>
      </dependency>

      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.3</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-simple</artifactId>
         <version>1.6.4</version>
         <scope>test</scope>
      </dependency>

   </dependencies>

   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-core</artifactId>
            <version>${project.version}</version>
         </dependency>

         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-client</artifactId>
            <version>${project.version}</version>
         </dependency>

         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-scanner</artifactId>
            <version>${project.version}</version>
         </dependency>

         <dependency>
            <groupId>com.somehost</groupId>
            <artifactId>tac-webapp</artifactId>
            <version>${project.version}</version>
         </dependency>
      </dependencies>
   </dependencyManagement>


 <profiles>
      <profile>
         <id>cobertura-instrument</id>
         <activation>
            <property>
               <name>cobertura-build</name>
            </property>
         </activation>
         <modules>
            <module>tac-cobertura</module>
         </modules>
         <build>
            <plugins>
               <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-source-plugin</artifactId>
                  <version>2.2.1</version>
                  <executions>
                     <execution>
                        <id>attach-sources</id>
                        <goals>
                           <goal>jar</goal>
                        </goals>
                     </execution>
                  </executions>
                  <inherited>true</inherited>
               </plugin>
            </plugins>
         </build>
         <dependencies>
            <dependency>
               <groupId>net.sourceforge.cobertura</groupId>
             <artifactId>cobertura-runtime</artifactId>
               <version>${cobertura.version}</version>
               <scope>provided</scope>
               <type>pom</type>
            </dependency>
         </dependencies>
      </profile>
   </profiles>


<build>
      <finalName>mac-${project.version}-r${buildNumber}</finalName>
      <pluginManagement>
         <plugins>
            <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>buildnumber-maven-plugin</artifactId>
               <version>1.0</version>
            </plugin>
             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.5.2</version>
                 <inherited>false</inherited>
                 <configuration>
                     <skip>true</skip>
                         <check>
                           <haltOnFailure>${coberturaHaltOnerror}</haltOnFailure>
                           <totalLineRate>90</totalLineRate>
                           <totalBranchRate>90</totalBranchRate>
                         </check>
                         <formats>
                           <format>html</format>
                         </formats>
                 </configuration>
                <executions>
                   <execution>
                      <id>instrument-code</id>
                      <phase>process-classes</phase>
                      <goals>
                         <goal>instrument</goal>
                      </goals>
                      <configuration>
                         <attach>true</attach>
                      </configuration>
                   </execution>
                </executions>
             </plugin>
         </plugins>
      </pluginManagement>

      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
               <execution>
                  <phase>validate</phase>
                  <goals>
                     <goal>create</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <useLastCommittedRevision>true</useLastCommittedRevision>
               <scmDirectory>${project.parent.basedir}</scmDirectory>
               <doCheck>false</doCheck>
               <doUpdate>false</doUpdate>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.6</version>
            <executions>
               <execution>
                  <id>bundle-manifest</id>
                  <phase>process-resources</phase>
                  <goals>
                     <goal>manifest</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <supportedProjectTypes>
                  <supportedProjectType>jar</supportedProjectType>
                  <supportedProjectType>bundle</supportedProjectType>
                  <supportedProjectType>war</supportedProjectType>
               </supportedProjectTypes>
               <instructions>
                  <Build-version>${buildNumber}</Build-version>
               </instructions>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
               <instrumentation>
                  <includes>
                     <include>com/somehost/**/*.class</include>
                  </includes>
                  <!--
                  <ignores>
                     <ignore>com.example.boringcode.*</ignore>
                  </ignores>
                  -->
                  <!--
                  <excludes>
                     <exclude>com/example/dullcode/**/*.class</exclude>
                     <exclude>com/example/**/*Test.class</exclude>
                  </excludes>
                  -->
               </instrumentation>
               <check>
                  <branchRate>85</branchRate>
                  <lineRate>85</lineRate>
                  <haltOnFailure>true</haltOnFailure>
                  <totalBranchRate>85</totalBranchRate>
                  <totalLineRate>85</totalLineRate>
                  <packageLineRate>85</packageLineRate>
                  <packageBranchRate>85</packageBranchRate>
                  <regexes>
                     <regex>
                        <pattern>com.somehost.*</pattern>
                        <branchRate>90</branchRate>
                        <lineRate>80</lineRate>
                     </regex>
                  </regexes>
               </check>
            </configuration>
            <executions>
               <execution>
                  <goals>
                     <goal>clean</goal>
                     <goal>check</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

   <reporting>
      <plugins>
         <plugin>
            <groupId>org.codehause.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
               <formats>
                  <format>html</format>
                  <format>xml</format>
               </formats>
            </configuration>
         </plugin>
      </plugins>
   </reporting>
</project>


更改之后,我会像这样运行它

mvn clean install -Dmaven.test.skip=true -Dmaven.it.skip=true -DcoberturaHaltOnError=false


而且,我仍然遇到相同的错误-

[INFO] --- cobertura-maven-plugin:2.5.2:check (default) @ tac-core ---
[INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 237 classes.

[ERROR] com.somehost.core.exception.LockedException failed check. Line coverage rate of 0.0% is below 80.0%
com.somehost.core.dao.impl.DAOReadOnlyImpl failed check. Branch coverage rate of 0.0% is below 90.0%
com.somehost.core.dao.impl.DAOReadOnlyImpl failed check. Line coverage rate of 0.0% is below 80.0%
com.somehost.core.service.Service failed check. Branch coverage rate of 0.0% is below 90.0%
com.somehost.core.service.Service failed check. Line coverage rate of 0.0% is below 80.0%
com.somehost.core.msg.client.StoreResponse failed check. Branch coverage rate of 0.0% is below 90.0%

// followed by other errors

最佳答案

将带有模块配置的插件移动到pluginManagement并添加以下内容

<project>
...
 <build>
  <pluginManagement>
   <plugins>
    <!-- put here your original plugin configuration for the children -->
    <plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>cobertura-maven-plugin</artifactId>
    </plugin>
   </plugins>
  </pluginManagement>
  <plugins>
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.5.2</version>
    <inherited>false</inherited>
    <configuration>
     <skip>true</skip>
    </configuration>
   </plugin>
  </plugins>
</build>




inherited=false使得仅可以为此项目设置配置,而不能将其用作父项目。

07-27 21:34