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

rbl8hiat  于 2022-11-28  发布在  Maven
关注(0)|答案(1)|浏览(129)

我有一个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的执行步骤。我所想到的是两个概要文件defaulte2eTests。使用default,我可以将activeByDefault设置为true并跳过e2 e测试。当我使用-P通过e2eTests时,我应该能够运行包括id=npm run e2e在内的所有执行
我试着把它们移到<profiles>,但是<sourceDirectory>抱怨了。我找到了一些像this这样的链接,但是问题是当我有<profiles><build>之外时,如何访问plugins
我不能正确地组织它。

chy5wohz

chy5wohz1#

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

<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.将e2 e测试的执行绑定到针对该测试设计的生命周期阶段(integration-test)-在这种情况下,mvn package不会触发e2 e测试:

...
<execution>
  <id>npm run e2e</id>
  <phase>integration-test</phase>
  <goals>
    <goal>npm</goal>
  </goals>
  <configuration>
    <arguments>run e2e</arguments>
  </configuration>
</execution>
...

1.或者利用propertiesprofiles,例如:
第一次

相关问题