这是我的pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
... dependencies ...
</dependencies>
<profiles>
<profile>
<id>suit1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<property>
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
<argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar" </argLine>
<suiteXmlFiles> <suiteXmlFile>src/test/java/Smartphones/suite1.xml</suiteXmlFile> </suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
我想在这里有很多个人资料。我要在其中哪一个中添加新的suite(number).xml
是否可以仅保留以下内容:
<suiteXmlFiles>
<suiteXmlFile>
src/test/java/Smartphones/suite1.xml
</suiteXmlFile>
</suiteXmlFiles>
在个人资料部分?并且不复制每个配置文件中的插件和依赖项吗?是否可以将这些信息移到上方?正确的做法是什么?
答案 0 :(得分:0)
配置文件是您在普通pom的顶部添加的内容,因此您应该仅将要更改的内容放入配置文件中。 在这种情况下,您可以移动主pom中的maven-compiler-plugin或allure-maven,仅复制surefire设置。 您也可以尝试在主pom的pluginManagement部分中移动surefire的依赖项。
如果由于某种原因不能在主pom中移动这些配置,则可以定义所有这些配置共有的e配置文件,并为每个suite.xml添加一个特定的配置文件。 在这种情况下,您将需要为每次执行启用两个概要文件,即common和suite。
答案 1 :(得分:0)
一切皆有可能!
这是您应该做的:
<build/>
的根目录(而不是pom.xml
的根目录中定义<profile/>
部分。<plugin/>
。不要定义<configuration/>
,而只使用<groupId/>
,<artifactId/>
和<version/>
,或者如果您确实定义了<configuration/>
,请确保它不适合您想要提取到<profile/>
的内容(例如,不要将<suiteXmlFiles/>
部分放在此处)。<profiles>
中定义仅针对<profile/>
的不同配置设置。考虑以下示例:
<project ....>
...
<build>
<pluginManagement>
<!-- pluginManagement is used to define the configuration
of your plugins and then inherit it
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<property>
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
<argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar"</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.9</version>
</plugin>
</pluginManagement>
<plugins>
<!-- When there is a pluginManagement section like the one above,
you can just invoke your plugins like without
any further configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- So, since you're now inheriting from the
pluginManagement section and you've declared that
your project uses these plugins, you can now extract
the suite configuration in a separate profile like this:
-->
<id>suite1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/java/Smartphones/suite1.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>