【问题标题】:Not able to build maven project due to test case execution failure由于测试用例执行失败,无法构建 maven 项目
【发布时间】:2017-12-13 11:27:04
【问题描述】:

由于未执行测试用例,我无法构建 maven 项目。 我越来越低于错误。我在 Jenkins 中也遇到了同样的错误,我无法执行构建,我必须跳过测试用例


Forking command line: cmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0_80\jre\bin\java" -XX:-UseSplitVerifier -jar D:\Ankush\Codes\RIN\0537-logistics-bit-c-rin\main\rin\rin-common\target\surefire\surefirebooter8137375113015923041.jar D:\Ankush\Codes\RIN\0537-logistics-bit-c-rin\main\rin\rin-common\target\surefire\surefire2656883459599824975tmp D:\Ankush\Codes\RIN\0537-logistics-bit-c-rin\main\rin\rin-common\target\surefire\surefire_083819702813080247tmp"
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:130)
at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:239)
at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:122)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:81)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Caused by: org.apache.maven.surefire.util.SurefireReflectionException: java.lang.ClassNotFoundException: org.sonar.java.jacoco.JUnitListener; nested exception is java.lang.ClassNotFoundException: org.sonar.java.jacoco.JUnitListener
at org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:236)
at org.apache.maven.surefire.util.ReflectionUtils.instantiate(ReflectionUtils.java:109)
at org.apache.maven.surefire.common.junit4.JUnit4RunListenerFactory.createCustomListeners(JUnit4RunListenerFactory.java:43)
at org.apache.maven.surefire.junit4.JUnit4Provider.<init>(JUnit4Provider.java:81)
... 10 more
Caused by: java.lang.ClassNotFoundException: org.sonar.java.jacoco.JUnitListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97)
at org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:228)
... 13 more

我的 POM 是这样的

<?xml version="1.0" encoding="UTF-8"?>
<!--
    JBoss, Home of Professional Open Source
    Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
    contributors by the @authors tag. See the copyright.txt in the
    distribution for a full listing of individual contributors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<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/maven-v4_0_0.xsd">


    <profiles>
        <!-- This section contains the properties that may vary from environment to environment.
            They are activated via profiles. -->

        <!-- Properties for use of variables, which shall be replaced by real values before deployment -->
        <profile>
            <id>var</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <isp.rin.ds.url>@@isp.rin.ds.url@@</isp.rin.ds.url>
                <isp.rin.ds.user>@@isp.rin.ds.user@@</isp.rin.ds.user>
                <isp.rin.ds.pwd>@@isp.rin.ds.pwd@@</isp.rin.ds.pwd>

                <isp.rin.ds.host>@@isp.rin.ds.host@@</isp.rin.ds.host>
                <isp.rin.ds.port>@@isp.rin.ds.port@@</isp.rin.ds.port>
                <isp.rin.ds.db>@@isp.rin.ds.db@@</isp.rin.ds.db>

                <isp.rin.activemq.transaction-support>@@isp.rin.activemq.transaction-support@@</isp.rin.activemq.transaction-support>
                <isp.rin.activemq.server-url.primary>@@isp.rin.activemq.server-url.primary@@</isp.rin.activemq.server-url.primary>
                <isp.rin.activemq.server-url.secondary>@@isp.rin.activemq.server-url.secondary@@</isp.rin.activemq.server-url.secondary>

                <isp.rin.logg.level>@@isp.rin.logg.level@@</isp.rin.logg.level>
                <isp.rin.business.logg.level>@@isp.rin.business.logg.level@@</isp.rin.business.logg.level>
                <isp.rin.message.logg.level>@@isp.rin.message.logg.level@@</isp.rin.message.logg.level>
            </properties>
        </profile>

        <!-- Properties for local developer machine -->
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <isp.rin.ds.url>jdbc:edb://localhost:37450/rin</isp.rin.ds.url>
                <isp.rin.ds.user>enterprisedb</isp.rin.ds.user>
                <isp.rin.ds.pwd>admin</isp.rin.ds.pwd>
                <isp.rin.ds.host>localhost</isp.rin.ds.host>
                <isp.rin.ds.port>37450</isp.rin.ds.port>
                <isp.rin.ds.db>dss</isp.rin.ds.db>

                <isp.rin.activemq.transaction-support>LocalTransaction</isp.rin.activemq.transaction-support>
                <isp.rin.activemq.server-url.primary>tcp://localhost:61616</isp.rin.activemq.server-url.primary>
                <isp.rin.activemq.server-url.secondary>tcp://localhost:61616</isp.rin.activemq.server-url.secondary>


                <isp.rin.logg.level>DEBUG</isp.rin.logg.level>
                <isp.rin.business.logg.level>DEBUG</isp.rin.business.logg.level>
                <isp.rin.message.logg.level>INFO</isp.rin.message.logg.level>

            </properties>
        </profile>
    </profiles>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.postnord.rin</groupId>
    <artifactId>rin-parent</artifactId>
    <version>1.4.0</version>
    <packaging>pom</packaging>
    <name>Parent project for rin-parent</name>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>

    <modules>
        <module>rin-common</module>
        <module>rin-xsd</module>
        <module>rin</module>
        <module>rin-ear</module>
    </modules>

    <properties>
        <!-- Explicitly declaring the source encoding eliminates the following message: -->
        <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
                resources, i.e. build is platform dependent! -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- JBoss dependency versions -->

        <version.jboss.maven.plugin>7.3.Final</version.jboss.maven.plugin>
                <!-- Define the version of JBoss' Java EE 6 APIs and Tools we want to import. -->
                <!-- Certified version of the JBoss EAP components we want to use -->
        <version.jboss.bom>1.0.2.Final-redhat-1</version.jboss.bom>
         <!--
        <version.jboss.as>7.2.0.Final</version.jboss.as>
        Alternatively, comment out the above line, and un-comment the 
            line below to use version 7.2.0.Final-redhat-8 which is a release certified 
            to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 
            maven repository. -->
        <!-- --><version.jboss.as>7.2.0.Final-redhat-8</version.jboss.as> 

         <!-- 
        <version.jboss.spec.javaee.6.0>3.0.2.Final</version.jboss.spec.javaee.6.0>
       Alternatively, comment out the above line, and un-comment the 
            line below to use version 3.0.2.Final-redhat-3 which is a release certified 
            to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 
            maven repository. -->
        <!-- <version.jboss.spec.javaee.6.0>3.0.1.Final-redhat-3</version.jboss.spec.javaee.6.0> -->
        <version.jboss.spec.javaee.6.0>3.0.1.Final-redhat-1</version.jboss.spec.javaee.6.0> 

        <!-- other plugin versions -->
        <version.compiler.plugin>2.3.2</version.compiler.plugin>
        <version.surefire.plugin>2.4.3</version.surefire.plugin>
        <version.ear.plugin>2.6</version.ear.plugin>
        <version.ejb.plugin>2.3</version.ejb.plugin>
        <version.war.plugin>2.1.1</version.war.plugin>
        <junit-version>4.12</junit-version>

        <!-- maven-compiler-plugin -->
        <maven.compiler.plugin>3.5.1</maven.compiler.plugin>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.release.plugin>2.5.3</maven.release.plugin>
        <maven.failsafe.plugin>2.19.1</maven.failsafe.plugin>
        <maven.surefire.plugin>2.19.1</maven.surefire.plugin>
        <jaxb2.maven.plugin.version>1.3</jaxb2.maven.plugin.version>

        <RIN.BITC.Name>RegisterItemNotifierBitC-${project.version}</RIN.BITC.Name>
        <RIN.PLE.Name>RinPLE-${project.version}</RIN.PLE.Name>
        <RIN.DB.PLE.Name>RinDbPLE-${project.version}</RIN.DB.PLE.Name>
        <RIN.LOG.PLE.Name>RinLogPLE-${project.version}</RIN.LOG.PLE.Name>
        <RIN.EAR.Name>rin</RIN.EAR.Name>
        <sonar.plugin.version>2.7</sonar.plugin.version>
        <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
        <sonar.junit.reportsPath>${basedir}/target/surefire-reports</sonar.junit.reportsPath>
        <sonar.language>java</sonar.language>
        <sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
        <jacoco.version>0.7.6.201602180812</jacoco.version>
        <sonar-jacoco-listeners.version>1.4</sonar-jacoco-listeners.version>
        <jacoco.outputDir>${basedir}/target/jacoco</jacoco.outputDir>
        <jacoco.out.ut.file>jacoco-ut.exec</jacoco.out.ut.file>
        <sonar.jacoco.reportPath>${jacoco.outputDir}/${jacoco.out.ut.file}</sonar.jacoco.reportPath>
        <jacoco.out.it.file>jacoco-it.exec</jacoco.out.it.file>
        <sonar.jacoco.itReportPath>${jacoco.outputDir}/${jacoco.out.it.file}</sonar.jacoco.itReportPath>

        <maven.build.helper.plugin.version>1.9</maven.build.helper.plugin.version>

    </properties>

    <dependencyManagement>
        <dependencies>

            <!-- Define the version of the EJB jar so that we don't need 
                to repeat ourselves in every module -->
            <dependency>
                <groupId>com.postnord.rin</groupId>
                <artifactId>rin</artifactId>
                <!--<version>0.0.1-SNAPSHOT</version>-->
                <version>${project.version}</version>
                <type>ejb</type>
            </dependency>

                        <!-- Define the version of JBoss' Java EE 6 APIs we want to import.
               Any dependencies from org.jboss.spec will have their version defined by this
               BOM -->
            <!-- JBoss distributes a complete set of Java EE 6 APIs including
                a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
                a collection) of artifacts. We use this here so that we always get the correct
                versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can
                read this as the JBoss stack of the Java EE 6 APIs). You can actually
                use this stack with any version of JBoss AS that implements Java EE 6, not
                just JBoss AS 7! -->
           <!--  <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>${version.jboss.spec.javaee.6.0}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency> -->

            <!-- JBoss distributes a complete set of Java EE 6 APIs including 
                a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or 
                a collection) of artifacts. We use this here so that we always get the correct 
                versions of artifacts. Here we use the jboss-javaee-6.0-with-tools stack 
                (you can read this as the JBoss stack of the Java EE 6 APIs, with some extras 
                tools for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate 
                stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras 
                from the Hibernate family of projects) -->
            <dependency>
                <groupId>org.jboss.bom</groupId>
                <artifactId>jboss-javaee-6.0-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.plugin}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
</exclusions>
</dependency>
            <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit-version}</version>
            <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.bom</groupId>
                <artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
            <groupId>org.codehaus.sonar-plugins.java</groupId>
            <artifactId>sonar-jacoco-listeners</artifactId>
            <version>${sonar-jacoco-listeners.version}</version>
            <scope>test</scope>
        </dependency>
                <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.plugin}</version>
        </dependency>

        </dependencies>
    </dependencyManagement>
<distributionManagement>
        <repository>
            <id>libs-release-local</id>
            <name>libs-release-local</name>
            <url>http://ella-neserv2.idp.posten.se:37081/artifactory/libs-release-local</url>
        </repository>
<snapshotRepository>
            <id>libs-snapshot-local</id>
            <name>libs-snapshot-local</name>
            <url>http://ella-neserv2.idp.posten.se:37081/artifactory/libs-snapshot-local</url>
        </snapshotRepository>
</distributionManagement>
    <build>
        <pluginManagement>
            <plugins>
                <!-- Compiler plugin enforces Java 1.6 compatibility and 
                    activates annotation processors -->
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${version.compiler.plugin}</version>
                    <configuration>
                        <source>${maven.compiler.source}</source>
                        <target>${maven.compiler.target}</target>
                    </configuration>
                </plugin>
                <!-- The JBoss AS plugin deploys your ear to a local JBoss 
                    AS container -->
                <!-- Due to Maven's lack of intelligence with EARs we need 
                    to configure the jboss-as maven plugin to skip deployment for all modules. 
                    We then enable it specifically in the ear module. -->
                <plugin>
                    <groupId>org.jboss.as.plugins</groupId>
                    <artifactId>jboss-as-maven-plugin</artifactId>
                    <version>${version.jboss.maven.plugin}</version>
                    <inherited>true</inherited>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin}</version>
                <configuration>
                    <argLine>${jacoco.agent.ut.arg}</argLine>
                    <!-- Specific to generate mapping between tests and covered code -->
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>org.sonar.java.jacoco.JUnitListener</value>
                        </property>
                    </properties>
                    <!-- test failure ignore -->
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.plugin}</version>
                <configuration>
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m ${jacoco.agent.it.arg}
                    </argLine>
                    <!-- Specific to generate mapping between tests and covered code -->
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>org.sonar.java.jacoco.JUnitListener</value>
                        </property>
                    </properties>
                    <!-- Let's put failsafe reports with surefire to have access to tests 
                        failures/success reports in sonar -->
                    <reportsDirectory>${project.build.directory}/surefire-reports
                    </reportsDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <!-- Prepares a variable, jacoco.agent.ut.arg, that contains the info 
                        to be passed to the JVM hosting the code being tested. -->
                    <execution>
                        <id>prepare-ut-agent</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                            <propertyName>jacoco.agent.ut.arg</propertyName>
                            <append>true</append>
                        </configuration>
                    </execution>
                    <!-- Prepares a variable, jacoco.agent.it.arg, that contains the info 
                        to be passed to the JVM hosting the code being tested. -->
                    <execution>
                        <id>prepare-it-agent</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.itReportPath}</destFile>
                            <propertyName>jacoco.agent.it.arg</propertyName>
                            <append>true</append>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar.plugin.version}</version>
            </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

版本是正确的,我也检查了其他 maven 项目 根据他们的说法,POM 看起来很正常,但这个问题仍然不会出现在其他组件构建中。

【问题讨论】:

  • 您是否使用 mvn clean install -U 命令清理了 maven 项目?当类没有定义时,会引发 ClassNotFoundException。

标签: java maven jenkins


【解决方案1】:

您在&lt;dependencyManagement&gt; 下配置了sonar-jacoco-listeners 依赖项。如果您希望此依赖于您的构建路径(以避免ClassNotFoundException),您必须在相应模块的&lt;build&gt;&lt;dependencies&gt;...&lt;/dependencies/&gt;&lt;/build&gt; 下定义它。确保您了解其中的区别:有关详细信息,请参阅 this postthe doc

这个项目似乎是其他项目的父项目。 Sonar 由您的子项目之一(您的模块之一)有效运行,您应该将 sonar-jacoco-listeners 定义为这些模块的依赖项(并将其保存在您的父依赖项管理中)。

【讨论】:

    【解决方案2】:

    您正在使用一个非常旧的 sonar-maven-plugin。你应该换成这个插件:

    <!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
    <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.4.0.905</version>
    </plugin>
    

    ...我不确定您是否也应该将其声明为 surefire 的 &lt;dependency&gt;(因为它必须提供给 surefire)

    另外,是的,您需要在&lt;plugins&gt; 中包含此定义(&lt;pluginManagement&gt; 是一种无需实际使用即可全局配置插件的方法。然后在&lt;plugins&gt; 中“激活”它)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-16
      • 2016-10-19
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      相关资源
      最近更新 更多