gpt4 book ai didi

Maven 配置文件 - 如何为父级和模块运行一次插件?

转载 作者:行者123 更新时间:2023-12-03 19:06:42 28 4
gpt4 key购买 nike

我对我的 Jenkins 输出感到有些困惑。

关于 Jenkins 的工作:(在底部缩短了 pom.xml)

mvn deploy -Pprofile1

我所有的插件将运行 4 次:
  • 父/pom.xml
  • 父/module1/pom.xml
  • 父/module2/pom.xml
  • 父/module3/pom.xml

  • 我需要:
  • 第一个 Maven 插件 : 只运行 一次在父 pom.xml
  • 第二个maven插件 : 运行 pom.xml

  • 为什么:
  • first-maven-plugin:将在阶段运行:初始化 --> 相当长的清理操作。不想要这个 4 次
  • second-maven-plugin: 将在 phase:package --> 所有 pom 中运行。

  • 父 pom.xml
    <project ...>

    <groupId>com.test.parent</groupId>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>parent</name>

    <modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
    </modules>

    <profiles>
    <profile>
    <id>profile1</id>
    <build>
    <plugins>
    <plugin>
    <groupId>com.test.plugin</groupId>
    <artifactId>first-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <execution>
    <id>execution1</id>
    <phase>initialize</phase>
    <goals>
    <goal>doit</goal>
    </goals>
    </execution>
    </plugin>
    <plugin>
    <groupId>com.test.plugin2</groupId>
    <artifactId>second-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <execution>
    <id>another</id>
    <phase>package</phase>
    <goals>
    <goal>goforit</goal>
    </goals>
    </execution>
    </plugin>
    </plugins>
    </build>
    </profile>
    </profiles>

    </project>

    最佳答案

    您可以使用 <inherited>false</inherited>在第一个插件配置中。所以它只会在父 pom 执行中运行。

    <build>
    <plugins>
    <plugin>
    <groupId>com.test.plugin</groupId>
    <artifactId>first-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <inherited>false</inherited>
    <execution>
    <id>execution1</id>
    <phase>initialize</phase>
    <goals>
    <goal>doit</goal>
    </goals>
    </execution>
    </plugin>
    <plugin>
    <groupId>com.test.plugin2</groupId>
    <artifactId>second-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <execution>
    <id>another</id>
    <phase>package</phase>
    <goals>
    <goal>goforit</goal>
    </goals>
    </execution>
    </plugin>
    </plugins>
    </build>

    https://stackoverflow.com/a/1671175

    关于Maven 配置文件 - 如何为父级和模块运行一次插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36216342/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com