1
votes

Last time I've decided to replace Cobertura plugin with JaCoCo plugin in my Java projects Maven builds.

One of them is a multimodule project with inter-module dependencies:

*-- pl.chilldev.commons
    |-- commons-concurrent
    |-- commons-daemon
    `-- commons-exception

The thing is that commons-daemon depends on commons-exception.

I have jacoco-maven-plugin configured following way:

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.1.201405082137</version>
            <executions>
                <execution>
                    <id>jacoco-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jacoco-report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Everything works, tests are run, but site target fails with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project commons: failed to get report for org.apache.maven.plugins:maven-javadoc-plugin: Failed to execute goal on project commons-daemon: Could not resolve dependencies for project pl.chilldev.commons:commons-daemon:jar:0.0.3-SNAPSHOT: Could not find artifact pl.chilldev.commons:commons-exception:jar:0.0.3-SNAPSHOT -> [Help 1]

Without jacoco-maven-plugin everything works fine even for site target.

1
are you running a mvn install or mvn packageJoseK
I wrote clearly, that it applies to target site.Rafał Wrzeszcz

1 Answers

2
votes

Managed to make it working. Problem is, that by default prepare-agent goal binds to initialize phase which means everything will be executing using JaCoCo java agent which probably is unable to resolve classpath before they are computed by Maven (I just assume that, I don't know internals).

Adding:

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.1.201405082137</version>
            <executions>
                <execution>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Fixed it.

BTW - It's also not needed to add report goal into executions list, I think it's more correct to add it into reporting plugins.