0

I am not able to build the maven project as the test cases are not being executed. I am getting below Error. Same Error I am getting in Jenkins as well there as well I am not able to execute the build and I have to skip the test cases


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

My POM look like this

<?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>

The Version Is correct and I have checked with other maven project as well POM looks normal according to them but still this issue never comes in other component build.

ank_rnk
  • 21
  • 4
  • Did you clean the maven project using mvn clean install -U command? ClassNotFoundException trows when there is no no definition for the class. – YAS_Bangamuwage Dec 13 '17 at 11:49

2 Answers2

0

You are using a very old sonar-maven-plugin. You should change to this 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>

... and I'm not sure if you should declare it as a surefire's <dependency> too (since it must be made available to surefire)

And additionnally yes, you need to include this definition in <plugins> (<pluginManagement> is a way to configure a plugin globally without actually using it. Then in <plugins> you 'activate' it)

spi
  • 1,673
  • 13
  • 19
0

You configured sonar-jacoco-listeners dependency under <dependencyManagement>. If you want this dependency on your build path (to avoid ClassNotFoundException) you must define it under <build><dependencies>...</dependencies/></build> of the corresponding module. Make sure you understand the difference: see this post and the doc for details.

This project seems to be a parent for other projects. Sonar is effectively run by one of your child project (one of your module), you should define sonar-jacoco-listeners as dependency of these modules (and keep it in your parent dependency management).

Pierre B.
  • 11,612
  • 1
  • 37
  • 58