简体   繁体   English

如何在POM文件中指定Maven命令行选项?

[英]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.

相关问题 如何为 maven 命令行附加 VM 选项 - How to attach VM options for maven command line 如何在聚合器POM中指定Maven属性? - How to specify maven properties in a aggregator POM? 如何在命令行中指定文本文件 - How to specify a text file in the command line 如何使用带有命令“idea pom.xml”的 Intellij 命令行工具导入 Maven 项目? - How to import a Maven project with Intellij Command line tool with command “idea pom.xml”? 如何通过命令行选项使用 Maven Surefire 排除标签? - How to exclude tags with Maven Surefire via command line options? 在maven pom.xml中,如何指定我要将“ .xml”文件复制到目标文件夹中? - In maven pom.xml, how to specify that I want to copy a “.xml” file into my target folder? Maven - 如何通过命令行为 java 项目创建 pom.xml - Maven - How to create a pom.xml for java project through command line 如何在maven pom.xml中定义属性并从命令行传递参数? - how to define property in maven pom.xml and pass arguments from command line? 如何通过pom.xml将Maven“ --also-make”选项传递给命令行 - How to pass maven “--also-make” option via pom.xml to command line 如何在pom中配置Maven-release-plugin以在命令行上模拟-Dgoals = deploy - How to configure the maven-release-plugin in pom to mimic -Dgoals=deploy on the command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM