如何在 POM 文件中指定 maven 命令行选项? [英] How to specify maven command line options in POM file?

查看:172
本文介绍了如何在 POM 文件中指定 maven 命令行选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目标,该目标将始终以某些参数运行.我不想一次又一次地指定它们并希望包含在 POM 文件中,这样即使另一个目标调用该目标,也会考虑执行这些参数.

I have a goal which will always run with certain parameters on. I don't want to specify them again and again and want to include in POM file so that even when another goal calls that goal then those parameters are considered for execution.

这些参数不应在全局范围内,因为它们仅用于测试范围.

These parameters shouldn't be in global scope as they are just for test scope.

我在 spring-boot 中有一个使用配置文件的代码.如果我使用 -Dspring.profiles.active=TEST 运行测试,则会出现预期结果.因此,使用 -Dspring.profiles.active=TEST 运行 failsafe:integration-test 目标是必需的.

I have a code in spring-boot which uses profiles. If I run the test with the -Dspring.profiles.active=TEST expected outcome occurs. So to run failsafe:integration-test goal with -Dspring.profiles.active=TEST is required.

推荐答案

这里有两个选项:在需要它们的测试中指定活动配置文件:

You have two options here: specify the active Profiles in the test that requires them:

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("TEST")
public class MyServiceTest {

    @Autowired
    MyService myService;

    @Test
    public void testServiceInitialized() throws Exception {
        // ...
    }

这也允许 IDE 直接运行测试.

this also allows the IDE to run the test directly.

选项二是让故障安全插件知道将该 -D 参数传递给测试:

Option two would be to let the failsafe plugin know to pass that -D parameter to the tests:

http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#argLine

因此,要么设置包含此参数的属性argLine",要么配置插件.使用这种方法,这些测试将仅使用 maven 运行 - 在 IDE 中,您可能必须重现此配置 - 有些聪明的人会自动执行此操作.

So either set a property "argLine" that contains this parameters or configure the plugin. With this approach those tests will only run using maven - in the IDE you may would have to reproduce this config - some are smart on will do this automatically.

如果您还需要告诉 spring boot 启用某些配置文件,则 spring-boot 插件允许直接执行此操作:http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html

If you also need to tell spring boot to enable some profiles the spring-boot plugin allows this directly: http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html

这篇关于如何在 POM 文件中指定 maven 命令行选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆