1

我正在尝试使用以下命令对我的父 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
4

2 回答 2

3

将插件及其模块的配置移动到 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使得可以仅为该项目设置配置,而不是那些将其用作父项目的配置。

于 2013-09-08T19:23:03.807 回答
2

让它更简单

mvn clean install -Dmaven.test.skip -Dcobertura.skip=true

这将跳过测试以及 cobertura 低覆盖率构建不会失败。通过从父项目执行此操作将有所帮助。一起跳过两者很重要,否则它将由于测试或由于cobertura而导致构建失败。

到目前为止,在没有改变任何东西的情况下,这是最简单的方法并且它奏效了。

于 2020-01-20T05:11:56.043 回答