英文:
How do I pass run command line arguments from Maven and Surefire plugin as properties in pom.xml?
问题
你可以使用以下命令来将命令行参数传递到pom.xml
文件中的属性:
mvn clean test -DargLine="-Dtestnames=iOS"
这将通过argLine
参数将-Dtestnames=iOS
传递给Surefire插件,以覆盖在pom.xml
文件中设置的默认值。
英文:
How do I pass arguments from command line to properties in pom.xml file?
I have the following pom file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>BusniessApp</groupId>
<artifactId>Test-Automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>testnames</name>
<value>Android,iOS</value>
</property>
</properties>
[...........]
</build>
<dependencies>
[...]
</dependencies>
</project>
I tired mvn clean test -Dtestnames=iOS
as stated in https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml but it still ran with the default value set in the pom.xml
答案1
得分: 0
我找到了解决方案,至少对我有效。我不得不在我的POM中创建一个属性,然后将其传递给构建部分。最终看起来像这样:
<properties>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<myArgument>默认值</myArgument>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<testnames>${myArgument}</testnames>
</properties>
</configuration>
</plugin>
</plugins>
</build>
英文:
Figured out the solution, at least one that works for me. I had to create a property in my POM then pass that to the build section.
Ended up looking like this
<properties>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<myArgument>DefaultValue</myArgument>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<testnames>${myArgument}</testnames>
</properties>
</configuration>
</plugin>
</plugins>
</build>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论