java 生成包含 Cobertura 报告的 Maven 站点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/596746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating a maven site including a Cobertura Report
提问by Trampas Kirk
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.
我有一些项目已经通过 Maven 进行站点生成,我想在其中集成 cobertura 报告,但是我似乎运行的 Maven 目标不会生成本地预览供我查看,其中包括 Cobertura 报告地点。在我将 pom 更改提交到 repo 并生成损坏的站点之前,我想确保它们生成正确。
Below is what I've added to the maven poms (parent and module), but the site I see when I run mvn site:rundoes not include the cobertura reports:
下面是我添加到 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 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?
我应该使用什么 maven 命令来生成带有 cobertura 报告的站点?或者,我应该(另外)添加什么以使站点生成包含 cobertura 报告?
采纳答案by Trampas Kirk
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.
maven站点生成插件中的链接生成似乎有很多错误。
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/sitetag to point to some local directory instead of the real-live deploy directory, then use maven site:deploy.
我发现让 maven 生成带有工作模块链接的站点的本地副本的唯一方法是修改distributionManagement/site标记以指向某个本地目录而不是实际部署目录,然后使用maven site:deploy.
Every attempt to use mvn site:stagegenerates broken links. Same goes for mvn site:run.
每次尝试使用都会mvn site:stage产生断开的链接。也一样mvn site:run。
The report links work with mvn site:run/ mvn site:stagebut the links to modules do not.
报告链接与mvn site:run/ 一起使用,mvn site:stage但模块链接不使用。
回答by Alex Miller
Should do:
应该做:
mvn site
To elaborate, running mvn a:bruns the goal b in plugin a. Saying mvn cmeans 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).
具体来说,运行mvn a:b 会运行插件 a 中的目标 b。说mvn c意味着运行生命周期阶段 c,它运行直到 c 的所有阶段中的所有绑定目标。因此,这将触发更多事情的发生(例如为生成 cobertura 报告做必要的准备)。
回答by Dave Moten
site:stage module links don't work in my experience either for multi module builds but site:deploy does. Try this:
根据我的经验,site:stage 模块链接对于多模块构建不起作用,但 site:deploy 可以。试试这个:
Use a property for the site URL in the parent pom, e.g. ${site.url}. Then call this
在父 pom 中使用站点 URL 的属性,例如${site.url}. 然后调用这个
mvn clean site site:deploy -Dsite.url=file://`pwd`/target/site-deployed
The pwdis a -nixcommand that will substitute the current directory. This is because the URL that you use must be absolute.
这pwd是一个-nix将替换当前目录的命令。这是因为您使用的 URL 必须是绝对的。
回答by André
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.
应该做你正在寻找的。您将插件配置为在生命周期的站点前和站点阶段运行,但您随后正在执行 site:run 目标而不是站点。我们正在用三叶草(商业覆盖工具)做类似的事情,而 mvn 站点可以解决问题。
回答by MetroidFan2002
mvn site:siteshould produce what you are after, in the target directory, there will be a site directory containing all reports linked with an index.htmlin that directory.
mvn site:site应该产生您想要的内容,在目标目录中,将有一个站点目录,其中包含与index.html该目录中的链接的所有报告。
回答by ScArcher2
We use
我们用
mvn site-deploy
This builds the site and deploys it (copies it to the place we have configured).
这将构建站点并部署它(将其复制到我们配置的位置)。

