基于配置文件使用插件和执行步骤



我有一个pom

<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>X.0.0</modelVersion>
<parent>
<groupId>asdasd</groupId>
<artifactId>asdasd</artifactId>
<version>0.334.0-SNAPSHOT</version>
<relativePath>../something/pom.xml</relativePath>
</parent>
<!-- ======================================================================= -->
<!-- P R O J E C T                                                           -->
<!-- ======================================================================= -->
<artifactId>dfdfd</artifactId>
<name>xxxxx</name>
<packaging>content-package</packaging>
<properties>
<sonar.sources>${basedir}/src/main/angular/src</sonar.sources>
<sonar.tests>${basedir}/src/main/angular/src</sonar.tests>
</properties>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/content/jcr_root</directory>
<excludes>
<exclude>**/*.iml</exclude>
</excludes>
<targetPath>jcr_root</targetPath>
</resource>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/content/META-INF/xxx/definition</directory>
<targetPath>../xxx/META-INF/vault/definition</targetPath>
</resource>
</resources>
<sourceDirectory>${basedir}/src/main/content/jcr_root</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
</plugin>
<!-- start frontend -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<inherited>false</inherited>
<configuration>
<nodeVersion>v16.17.0</nodeVersion>
<npmVersion>8.15.0</npmVersion>
<nodeDownloadRoot>xxxxx</nodeDownloadRoot>
<npmDownloadRoot>xxxxx</npmDownloadRoot>
<installDirectory>src/main/angular</installDirectory>
<workingDirectory>src/main/angular</workingDirectory>
</configuration>
<executions>
<execution>
......
</execution>
<execution>
<id>npm rebuild node-sass</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>rebuild node-sass</arguments>
</configuration>
</execution>
<execution>
<id>npm run e2e</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- end frontend -->
</plugins>
</build>

</project>

我想基于配置文件运行id为npm run e2e的执行步骤。我想到的是2个剖面defaulte2eTests。对于default,我可以将activeByDefault设置为true并跳过e2e测试。当我使用-P传递e2eTests时,我应该能够运行所有的执行,包括id=npm run e2e

我试图将它们移动到<profiles>,但随后<sourceDirectory>抱怨。我发现了一些这样的链接,但问题是如何访问plugins当我有<profiles>以外的<build>

我不能正确地组织它。

通常,不需要将整个<build>配置复制到配置文件定义中-只需定义额外的插件执行就足够了,例如。像这样:

<profiles>
<profile>
<id>e2eTests</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<executions>
<execution>
<id>npm run e2e</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

但是,我将以不同的方式配置它:

  1. 将端到端测试的执行绑定到为此设计的生命周期阶段(integration-test)—在这种情况下,mvn package不会触发端到端测试:
...
<execution>
<id>npm run e2e</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
...
  1. 或者利用propertiesprofiles,例如:
<properties>
...
<skip.e2e>true</skip.e2e>
...
</properties>
<profiles>
<profile>
<id>e2eTests</id>
<properties>
<skip.e2e>false</skip.e2e>
</properties>
</profile>
</profiles>
...
<execution>
<id>npm run e2e</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<skip>${skip.e2e}</skip>
<arguments>run e2e</arguments>
</configuration>
</execution>
...

最新更新