问题描述
我在我的项目我的src /测试/ java文件夹我使用的是测试一些类。当我使用运行Maven标准的Maven插件进行编译。这些项目被编译成.class文件,并包含在编译code包装罐。
我已经创建了这些测试自己的Eclipse中运行,运行Maven和建设我发布之前。他们只是理智测试,不应该被包括在生成。我宁愿不把它们放在一个单独的项目,因为对我来说,他们在这里是有意义的。我怎么可以告诉大家,我不希望它来编译行家/包含的文件在该目录中?
我beleive Maven的编译器插件生成JAR如下:
<&插件GT;
<&的artifactId GT; Maven的编译器插件< / artifactId的>
<结构>
<信源> 1.6 LT; /源>
<目标> 1.6 LT; /目标与GT;
< /结构>
< /插件>
我从这个答案您如下:
<&插件GT;
<&的groupId GT; org.apache.maven.plugins< /的groupId>
<&的artifactId GT;的maven-JAR-插件< / artifactId的>
<&版GT; 2.4< /版本>
<结构>
<&排除GT;
<&排除GT; ** / yoursortoftestpackage / YourSortOfTestClass * LT; /排除>
< /排除>
< /结构>
< /插件>
希望帮助!
干杯,
I have some classes I'm using as tests in my src/test/java folder of my project. When I run maven using the standard maven compile plugin. Those items are compiled into .class files and are included in the jar where the compiled code is packaged.
I've created these tests for myself to run within eclipse, prior to running maven and building my release. They are just sanity tests and should not be included in the build. I'd rather not put them in a seperate project, because, to me, they make sense here. How can I tell maven that I do not want it to compile/include the files in that directory?
I beleive the maven compiler plugin is generating the jar as follows:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I understand from your comment on this answer that the "tests" aren't unit tests, but just ordinary classes that you want excluded from the final artifact? As such, your best option is to make use of the <exclude>
tag with the maven-jar-plugin as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/yoursortoftestpackage/YourSortOfTestClass*</exclude>
</excludes>
</configuration>
</plugin>
Hope that helps!
Cheers,
这篇关于Maven的:剔除构建测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!