Domanda

I know there are lot of questions about Sonar and Jacoco not generating the report correctly on SO but none of them helped me solve my problem:

Here is the deal :

I have a project using Cobertura to calculate code coverage and I can't change that. Sonar must use Cobertura for the server-side. But on the other hand I have this client (we're talking about a webapplication using smartGWT in java) which is tested with Selenium RC (because that's the only way to test smartGWT).

Cobertura can't calculate Selenium tests' coverage because those tests are done on the deployed application. Jacoco can calculate that because it is launched as a java agent. So everything is working fine on my computer. The jacoco.exec is generated successfully. But it seems that Sonar can't find how to read that file or maybe it's just cobertura and jacoco that are conflicted...

Here is the error that Jenkins generate :

[INFO] Surefire report directory: D:\JENKINS-SONAR\jobs\agepro PROTO\workspace\target\surefire-reports
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
Caused by: java.io.FileNotFoundException: D:\JENKINS-SONAR\jobs\agepro (Accès refusé)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
    at org.jacoco.agent.rt_9w37ty.controller.LocalController.startup(LocalController.java:46)
    at org.jacoco.agent.rt_9w37ty.JacocoAgent.init(JacocoAgent.java:83)
    at org.jacoco.agent.rt_9w37ty.JacocoAgent.premain(JacocoAgent.java:165)
    ... 6 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main" 

And here is my configuration of the surefire plugin :

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath}</argLine>
                    <excludes>
                        <exclude>**/Selenium*.java</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>surefire-integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <!-- <argLine>-javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath}</argLine> -->
                            <excludes>
                                <exclude>none</exclude>
                            </excludes>
                            <includes>
                                <include>**/Selenium*.java</include>
                            </includes>
                            <goal>selenium-test</goal>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Do you see any mistake I could have made ? Or maybe I have to set another path for the jacoco jar or something else ? Thanks for your help anyway.

È stato utile?

Soluzione

The name reportPath is a bit misleading.

The setting sonar.jacoco.reportPath needs to point to a file and not to a directory.

You seem to have set it to: D:\JENKINS-SONAR\jobs\agepro: But I think you mean D:\JENKINS-SONAR\jobs\agepro\jacoco.exec

On further inspection I noticed that the problem might be that you working directory "agepro PROTO" has a space in it.

This breaks the syntax for the java agent configuration. Can you get rid of the space(I don't know if destfile='${sonar.jacoco.reportPath}' would work)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top