[英]How to specify maven command line options in POM file?
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. 我不想一次又一次地指定它们,并且不想包含在POM文件中,这样即使当另一个目标调用该目标时,也可以考虑使用这些参数来执行。
These parameters shouldn't be in global scope as they are just for test scope. 这些参数不应该在全局范围内,因为它们仅用于测试范围。
I have a code in spring-boot which uses profiles. 我在spring-boot中有一个使用配置文件的代码。 If I run the test with the -Dspring.profiles.active=TEST
expected outcome occurs. 如果我使用-Dspring.profiles.active=TEST
运行测试,则会出现预期的结果。 So to run failsafe:integration-test
goal with -Dspring.profiles.active=TEST
is required. 因此,运行带有-Dspring.profiles.active=TEST
failsafe:integration-test
目标是必需的。
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 {
// ...
}
this also allows the IDE to run the test directly. 这也使IDE可以直接运行测试。
Option two would be to let the failsafe plugin know to pass that -D parameter to the tests: 第二种方法是让故障安全插件知道将-D参数传递给测试:
http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#argLine http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#argLine
So either set a property "argLine" that contains this parameters or configure the plugin. 因此,要么设置包含此参数的属性“ argLine”,要么配置插件。 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. 使用这种方法,这些测试将仅使用maven运行-在IDE中,您可能必须重现此配置-有些聪明的人会自动执行此操作。
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 如果您还需要告诉Spring Boot启用某些配置文件,则spring-boot插件可以直接允许这样做: http : //docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.