m2e何时以及如何使用Maven测试范围在Eclipse Run Configurations中包括测试依赖项? [英] When and how does m2e use the Maven test scope to include test dependencies in Eclipse Run Configurations?
问题描述
我花了一些时间进行观察,但是我发现m2e是神奇地"管理着类路径.
It took me a while to make this observation, but I see that m2e "magically" manages the classpath.
示例: 如果我在"src/java/main"源文件夹中作为Java应用程序运行,则它将排除"test"作用域.注意:该类能够编译,但无法运行.但是,如果我将同一类移到"src/java/test"文件夹中,则它可以编译并运行.
Examples: If I Run as a Java application in the "src/java/main" source folder it excludes "test" scope. Note: The class was able to compile, but not able to run. But if I move that same class to the "src/java/test" folder then it is able to compile and run.
如果我Run as JUnit Test
,则始终包括测试"范围(即使该类位于主"源文件夹中).
If I Run as JUnit Test
then the "test" scope is always included (even if the class is in the "main" source folder).
我做这些发现的唯一方法是在运行时转储java.class.path系统属性.
The only way I made these discover is by dumping the java.class.path system property at runtime.
我在 http://www.eclipse.org/m2e中找到了以下内容/documentation/m2e-faq.html
还要注意,用于JUnit和Java应用程序启动的类路径 启用了Maven支持的项目的配置也是 以特殊方式计算并且排除的资源不影响它 要么.
Also note, that classpath used for JUnit and Java Application launch configurations for projects that have Maven support enabled is also calculated in a special way and excluded resources does not affect it either.
比较它们的运行配置时,看不到任何差异,那么如何查看正在执行的魔术呢?
有没有一种方法可以通过运行配置"或任何其他方式来覆盖正常"行为?
I cannot see any differences when I compare their Run Configurations, so how can I see what magic is being performed?
And is there a way to override the "normal" behavior via the Run Configuration or any other means?
推荐答案
从 https://bugs.eclipse.org/bugs/show_bug.cgi?id=410228 :
这是m2e决定Java应用程序启动应使用测试还是运行时工件范围的方式.
Here is how m2e decides if java application launch should use test or runtime artifact scopes.
- 以junit测试运行"和以testng测试运行"使用测试范围.
- 如果应用程序主类位于src/test/java下,则以Java应用程序运行"使用测试范围,否则使用运行时范围.
这意味着您可以使用主类的位置来控制行为.
This means you can control the behavior using the location of the main class.
这篇关于m2e何时以及如何使用Maven测试范围在Eclipse Run Configurations中包括测试依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!