Setting properties via Maven command line

后端 未结 2 1680
生来不讨喜
生来不讨喜 2020-12-30 11:55

I\'m confused about the correct way to set a property for some unit tests via the command line when using Maven. There are a number of questions (e.g. Specifying Maven memor

相关标签:
2条回答
  • 2020-12-30 12:23

    Yes, you should have

    mvn package -DargLine="-Djava.util.logging.config.class=someClass"
    

    Notice the addition of -D inside the argLine.

    Let's explain why. argLine is indeed an attribute of the maven-surefire-plugin with the corresponding user property argLine. This means that you can set this property directly on the command line with -DargLine. But then, the value of that property is -Djava.util.logging.config.class=someClass. This is exactly what you had when you configured the plugin in the POM directly with

    <argLine>-Djava.util.logging.config.class=someClass</argLine>
    

    Additionally, when you call

    mvn package -Djava.util.logging.config.class=someClass
    

    then you are not setting the argLine property. You are adding a system property.

    0 讨论(0)
  • 2020-12-30 12:35

    Regarding your approach to configuring tests

    If you want to pass in configuration to your tests, use for example a file in src/test/resources/myTestConfig.xml. Or use the enhanced features of Test-ng. Your tests will have no value on the centralized build server, or those who want to run/test your code, where config values can't be changed (easily).

    The recommended usage of command-line arguments for Maven is for configuring the Maven plugins, build environment and Java config for the build. Use as little features, config and plugins as possible. Or you'll face a ton of issues down the line, and the tweak-all-you-want-A-standardized-build-doesn't-mean-sh*t-for-me-Gradle will feel more comfortable.

    0 讨论(0)
提交回复
热议问题