gpt4 book ai didi

eclipse - m2e 何时以及如何使用 Maven 测试范围在 Eclipse 运行配置中包含测试依赖项?

转载 作者:行者123 更新时间:2023-12-02 10:42:36 25 4
gpt4 key购买 nike

我花了一段时间才做出这个观察,但我发现 m2e “神奇地”管理了类路径。

示例:如果我在“src/java/main”源文件夹中作为 Java 应用程序运行,它将排除“test”范围。注意:该类能够编译,但无法运行。但是,如果我将同一个类移至“src/java/test”文件夹,那么它就能够编译并运行。

如果我作为 JUnit Test 运行,则始终包含“测试”范围(即使该类位于“主”源文件夹中)。

我发现这些的唯一方法是在运行时转储 java.class.path 系统属性。

我在 http://www.eclipse.org/m2e/documentation/m2e-faq.html 找到了以下内容

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.

当我比较它们的运行配置时,我看不到任何差异,那么我如何才能看到正在执行什么魔法?
有没有办法通过运行配置或任何其他方式覆盖“正常”行为?

最佳答案

引用自https://bugs.eclipse.org/bugs/show_bug.cgi?id=410228 :

Here is how m2e decides if java application launch should use test or runtime artifact scopes.

  • "run as junit test" and "run as testng test" uses test scope.
  • "run as java application" uses test scope if application main class is located under src/test/java, otherwise uses runtime scope.

这意味着您可以使用主类的位置来控制行为。

关于eclipse - m2e 何时以及如何使用 Maven 测试范围在 Eclipse 运行配置中包含测试依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41031421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com