为什么Jenkins将检测jar提升到我的存储库

时间:2015-06-22 13:34:20

标签: maven jenkins cobertura maven-cobertura-plugin

我有一个问题,Jenkins将一个已检测的jar文件提升到nexus存储库,所以当它在jBoss中部署我的应用程序时抛出异常Caused by: java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/TouchCollector at com.premierinc.its.pfgpgrouper.service.algorithms.AbstractPopulationGrouper.__cobertura_init

Jenkins maven配置: 版本是mvn-3.2.3 清理安装站点

我的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.myapp.its</groupId>
<artifactId>myapp</artifactId>
<version>15.2.2.0-SNAPSHOT</version>

<packaging>jar</packaging>

<name>MyApp</name>
<description>
   MY API.
</description>

<scm>
    <connection>scm:git:ssh://git@code/pfpg/my-app.git</connection>
    <developerConnection>scm:git:ssh://git@code/pfgp/my-app.git</developerConnection>
    <tag>HEAD</tag>
</scm>

<distributionManagement>
    <repository>
        <id>code-artifacts</id>
        <url>
            http://code/artifacts/content/repositories/releases
        </url>
    </repository>
    <snapshotRepository>
        <id>code-artifacts</id>
        <url>
            http://code/artifacts/content/repositories/snapshots
        </url>
    </snapshotRepository>
</distributionManagement>

<properties>
    <spring.version>4.0.3.RELEASE</spring.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <oracle.version>11.2.0.2.0</oracle.version>
</properties>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
                <argLine>-Xms512m -Xmx512m</argLine>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <formats>
                    <format>xml</format>
                    <format>html</format>
                </formats>
            </configuration>
            <executions>
                <execution>
                    <phase>site</phase>
                    <goals>
                        <goal>cobertura</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-jgitflow-plugin</artifactId>
            <version>1.0-alpha21.1</version>
            <configuration>
                <autoVersionSubmodules>true</autoVersionSubmodules>
                <pushFeatures>true</pushFeatures>
                <pushHotfixes>true</pushHotfixes>
                <pushReleases>true</pushReleases>
                <noReleaseBuild>true</noReleaseBuild>
                <noFeatureBuild>true</noFeatureBuild>
                <noHotfixBuild>true</noHotfixBuild>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>1.3</version>

            <executions>
                <execution>
                    <id>myFile</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <schemaDirectory>src/main/resources/schema</schemaDirectory>
                        <outputDirectory>src/main/java/</outputDirectory>
                        <extension>true</extension>
                        <arguments>
                            -no-header -cp collection-setter-injector.jar
                            -Xcollection-setter-injector
                        </arguments>
                        <packageName>com.premierinc.its.pfgpgrouper.dto</packageName>
                        <staleFile>
                            ${project.build.directory}/generated-sources/jaxb/patient/.staleFlag
                        </staleFile>

                        <clearOutputDir>false</clearOutputDir>
                    </configuration>
                </execution>

            </executions>
            <dependencies>
                <dependency>
                    <groupId>net.java.dev.vcc.thirdparty</groupId>
                    <artifactId>collection-setter-injector</artifactId>
                    <version>0.5.0-1</version>
                </dependency>
            </dependencies>

        </plugin>

    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>


</build>


<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.7</version>
        </plugin>
        <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> 
            <version>2.10.1</version> </plugin> -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.17</version>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>

        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.2</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.13</version>
            <configuration>
                <configLocation>src/code-analysis/checkstyle.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>

</reporting>

<dependencies>
    <!-- DB Driver -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6g</artifactId>
        <version>${oracle.version}</version>
    </dependency>

    <!-- SPRING -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-mock</artifactId>
        <version>2.0.8</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>5.14.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.10.19</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.10</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.2</version>
    </dependency>

</dependencies>

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题; Maven 3.2.3,cobertura-maven-plugin 2.7,Jenkins 1.608。这似乎是詹金斯问题,而不是cobertura问题。

我的jenkins工作在主要构建步骤中运行maven目标clean verify site:site

Jenkins然后将verify期间生成的工件部署到maven存储库,但是,jar中的类都由Cobertura检测,在运行时导致NoClassDefFoundErrors,因为Java EE容器没有知道Cobertura课程。

我尝试将maven调用clean package添加为构建后步骤,但这并没有改变任何内容 - Jenkins以某种方式保存了在主步骤中构建的工件并且仅部署了这个,忽略了在post-built中构建的工件建立步骤。

现在对我有用的是完全禁用Jenkins的“部署工件”选项,让它运行后构建mvn clean deploy。但是,您必须添加-DskipTests=true,否则您的所有单元和集成测试都将再次运行。

答案 1 :(得分:0)

他们在最新版本中修复了cobertura的问题,请参阅此link