如何更改 Maven 2 / Cobertura 工具目标的默认输出?
当我使用 Maven 2 使用命令来检测我的类时
mvn cobertura:仪器
输出(检测的类)放在 \target\ generated-classes 中。有没有办法将输出位置更改为\target\classes?
我检查了 cobertura-maven 插件的检测任务,但这到目前为止还没有给我一个解决方案。
when i instrument my classes using Maven 2 using the command
mvn cobertura:instrument
The output (the instrumented classes) are put in \target\generated-classes. Is there a way to change the output location to \target\classes?
I checked the instrumentation tasks of the cobertura-maven plugin but this does not give me a solution sofar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您还没有说明为什么要覆盖默认位置,但我认为您可以使用其他项目中的检测类,或者将它们包含在 Web 存档或类似的内容中。
我将以下内容添加到我的 pom.xml
这使得 maven 生成一个名为 projectname-instrumented.jar 的附加 jar 文件
然后可以使用
我没有测试的 任何其他 pom(包括例如 Web 模块)依赖此 jar 文件这 100% 但过去使用过类似的机制
You have not said why you want to overwrite the default location, but I assume it is so that you can use the instrumented classes from another project, or perhaps include them in a web archive or something similar.
I added the following to my pom.xml
This makes maven generate an additional jar file called projectname-instrumented.jar
It is then possible to depend on this jar file from any other pom (including for example a web module) using
I did not test this 100% but have used similar mechanisms in the past
据我了解,cobertura 仅需要仪器类来生成报告。如果您在
target/classes
中创建它们,它们将覆盖原始的类文件。如果您需要 jar 中的检测文件,您可以配置
maven-jar-plugin
来从target/ generated-classes
目录中获取文件标准${build.project.outputDirectory}
中的文件或除此之外的文件。编辑
看看 maven-jar -插件描述。要仅使用
target/ generated-classes
,您的 POM 中的以下添加应该可以工作 - 尝试并根据您的需要进行修改:${project.build.directory}
点到您的目标文件夹,${project.build.ouputDirectory}
到 target/classes。我不知道您是否可以简单地将${project.build.ouputDirectory}
设置为新值 - 看看 maven book的这一章,也许你会发现一些提示编辑2
或者或者另外,您可以在 coberture:instrument 完成后使用 maven 将文件从 target/ generated-classes 复制到 target/classes 。 这个问题有一个答案和一个例子POM(片段),您只需要确定正确的阶段(流程资源对于您的情况来说肯定太早了)
As far as I understand, the instrumented classes are only needed by cobertura for report generation. If you create them in
target/classes
, they will overwrite the original class files.If you need the instrumented files in a jar as a result, you can configure the
maven-jar-plugin
to pick up the files from thetarget/generated-classes
directory instead of or in addition to the files from the standard${build.project.outputDirectory}
.Edit
Have a look at the maven-jar-plugin description. To only use
target/generated-classes
, the following addition to your POM should work - try it and modify it to your needs:${project.build.directory}
points to your target folder,${project.build.ouputDirectory}
to target/classes. I do not know if you can simply set${project.build.ouputDirectory}
to a new value - have a look at the this chapter of the maven book, maybe you find some hintsEdit 2
Alternativly or additionally you can use maven to copy the files from target/generated-classes to target/classes after
coberture:instrument
has finished. This question has one answer with an example POM (fragment), you just have to identify the correct phase (process-resources is definitely too early for your case)您是否尝试过“mvn cobertura:仪器安装”?它将生成一个包含所有 cobertura 版本类的 jar 文件。
如果您想改回原始版本,只需运行不带“cobertura:instrument”的命令即可。
Did you try "mvn cobertura:instrument install"? It will generate a jar file including all the cobertura version classes.
If you want to change back original version, just run the command without "cobertura:instrument".
我刚刚实现了 Andreas_D 提出的解决方案,修改了我的 pom 并使用了 maven-resources-plugin。因此,在我构建的某个阶段,Cobertura 生成的文件被复制到 /target/classes 目录。
I just implemented the solution proposed by Andreas_D, modified my pom and uses the maven-resources-plugin. So on some stage of my build the Cobertura generated files are copied to the /target/classes directory.
您可以使用
[Your DIR]
进行配置You can configure it using
<classesDirectory>[Your DIR]</classesDirectory>
在 cobertura-maven-plugin 版本 2.4 中,这仍然不受支持。我刚刚创建了一个改进票,补丁已附加到票中。
In cobertura-maven-plugin version 2.4 this is still not supported. I've just created an improvement ticket, patch is attached to the ticket.