生成一个 Maven 站点,包括 Cobertura 报告

发布于 2024-07-14 03:48:22 字数 2540 浏览 11 评论 0原文

我有一些项目已经通过 Maven 进行站点生成,并且我想在其中集成 Cobertura 报告,但我似乎运行的 Maven 目标都不会生成本地预览供我查看,其中包括 Cobertura 报告地点。 我想在将 pom 更改提交到存储库并生成损坏的站点之前确保它们正确生成。

下面是我添加到 Maven poms(父级和模块)中的内容,但是当我运行 mvn site:run 时看到的站点不包括 cobertura 报告:

<project>
...
    <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <configuration>
                <check>
                    <haltOnFailure>false</haltOnFailure>
                    <regexes>
                        <regex>
                            <pattern>parent-package-name-here.*</pattern>
                            <branchRate>80</branchRate>
                            <lineRate>80</lineRate>
                        </regex>
                    </regexes>
                </check>
                <instrumentation>
                    <includes>
                        <include>parent-package-name-here/**/*.class</include>
                    </includes>
                </instrumentation>
            </configuration>
            <executions>
                <execution>
                    <id>clean</id>
                    <phase>pre-site</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>instrument</id>
                    <phase>site</phase>
                    <goals>
                        <goal>instrument</goal>
                        <goal>cobertura</goal>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
...
<reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
        </plugins>
</reporting>
...
</project>

What maven command I should use to生成带有 cobertura 报告的站点? 或者,我应该(另外)添加什么以使站点生成包含 cobertura 报告?

I've got some projects that are already doing site generation via maven, and I want to integrate cobertura reports in them, but no maven goal I seem to run will generate a local preview for me to look at that includes the Cobertura reports in the site. I want to be sure they're generating correctly before I commit the pom changes to the repo and have broken site generated.

Below is what I've added to the maven poms (parent and module), but the site I see when I run mvn site:run does not include the cobertura reports:

<project>
...
    <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <configuration>
                <check>
                    <haltOnFailure>false</haltOnFailure>
                    <regexes>
                        <regex>
                            <pattern>parent-package-name-here.*</pattern>
                            <branchRate>80</branchRate>
                            <lineRate>80</lineRate>
                        </regex>
                    </regexes>
                </check>
                <instrumentation>
                    <includes>
                        <include>parent-package-name-here/**/*.class</include>
                    </includes>
                </instrumentation>
            </configuration>
            <executions>
                <execution>
                    <id>clean</id>
                    <phase>pre-site</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>instrument</id>
                    <phase>site</phase>
                    <goals>
                        <goal>instrument</goal>
                        <goal>cobertura</goal>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
...
<reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
        </plugins>
</reporting>
...
</project>

What maven command should I use to generate the site with cobertura reports? Or, what should I add (additionally) to get the site generation to include the cobertura reports?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

獨角戲 2024-07-21 03:48:22

应该做:

mvn site

详细来说,运行 mvn a:b 运行插件 a 中的目标 b。 说mvn c意味着运行生命周期阶段c,它运行直到c的所有阶段中的所有绑定目标。 因此,这将引发更多事情发生(例如为生成 cobertura 报告进行必要的准备)。

Should do:

mvn site

To elaborate, running mvn a:b runs the goal b in plugin a. Saying mvn c means to run the lifecycle phase c, which runs all of the bound goals in all of the phases up to c. As a result, this will trigger a lot more things to happen (such as doing the necessary preparation to produce cobertura reports).

绝情姑娘 2024-07-21 03:48:22

我想出了如何做到这一点。

Maven 站点生成插件中的链接生成似乎存在很多错误。

我发现让 Maven 生成具有工作模块链接的站点本地副本的唯一方法是修改 distributionManagement/site 标记以指向某个本地目录而不是实际部署目录,然后使用maven site:deploy

每次尝试使用 mvn site:stage 都会生成损坏的链接。 mvn site:run 也是如此。

报告链接可与 mvn site:run / mvn site:stage 配合使用,但模块链接则不行。

I figured out how to do this.

It seems there are a lot of bugs in the link generation within the maven site generation plugin.

The only way I've found to make maven generate a local copy of the site with working module links is to modify the distributionManagement/site tag to point to some local directory instead of the real-live deploy directory, then use maven site:deploy.

Every attempt to use mvn site:stage generates broken links. Same goes for mvn site:run.

The report links work with mvn site:run / mvn site:stage but the links to modules do not.

独行侠 2024-07-21 03:48:22
mvn site

应该做你正在寻找的事情。 您将插件配置为在生命周期的预站点和站点阶段运行,但您随后执行的是站点:运行目标而不是站点。 我们正在使用 clover(商业报道工具)做类似的事情,而 mvn site 则可以做到这一点。

mvn site

should do what you are looking for. You configure the plugin to run in the pre-site and site phases of the life cycle but your are then executing the site:run goal not site. We are doing similar things with clover (commercial coverage tool) and mvn site does the trick.

桃扇骨 2024-07-21 03:48:22

根据我的经验,site:stage 模块链接对于多模块构建不起作用,但 site:deploy 可以。 试试这个:

在父 pom 中使用站点 URL 的属性,例如 ${site.url}。 然后调用此

mvn clean site site:deploy -Dsite.url=file://`pwd`/target/site-deployed

pwd 是一个 -nix 命令,它将替换当前目录。 这是因为您使用的 URL 必须是绝对的。

site:stage module links don't work in my experience either for multi module builds but site:deploy does. Try this:

Use a property for the site URL in the parent pom, e.g. ${site.url}. Then call this

mvn clean site site:deploy -Dsite.url=file://`pwd`/target/site-deployed

The pwd is a -nix command that will substitute the current directory. This is because the URL that you use must be absolute.

谷夏 2024-07-21 03:48:22

我们使用

mvn site-deploy

This 构建站点并部署它(将其复制到我们配置的位置)。

We use

mvn site-deploy

This builds the site and deploys it (copies it to the place we have configured).

踏月而来 2024-07-21 03:48:22

mvn site:site 应该生成您想要的内容,在目标目录中,将有一个站点目录,其中包含与该目录中的 index.html 链接的所有报告。

mvn site:site should produce what you are after, in the target directory, there will be a site directory containing all reports linked with an index.html in that directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文