jacoco-maven-plugin causes site plugin to fail in multimodule project

∥☆過路亽.° 提交于 2019-12-23 03:48:08

问题


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:


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.



来源:https://stackoverflow.com/questions/23927329/jacoco-maven-plugin-causes-site-plugin-to-fail-in-multimodule-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!