相关疑难解决方法(0)

在父模块上执行Maven插件目标,但不在子模块上执行

我们有一个多模块maven项目,它使用一个定义buildnumber-maven-plugin的配置文件来增加内部版本号,然后将其检入源代码控制.

如果我在父pom.xml中定义插件,它也会为所有子构建执行.

这是我的父pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.webwars</groupId>
  <artifactId>parent</artifactId>
  <packaging>pom</packaging>
  <properties>
    <buildNumber.properties>${basedir}/../parent/buildNumber.properties</buildNumber.properties>
  </properties>
  <version>1.0-SNAPSHOT</version>
  <name>Parent Project</name>
  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <debug>false</debug>
              <optimize>true</optimize>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0-beta-3</version>
            <executions>
              <execution>
                <phase>validate</phase>
                <goals>
                  <goal>create</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <buildNumberPropertiesFileLocation>${buildNumber.properties}</buildNumberPropertiesFileLocation>
              <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
              <doCheck>false</doCheck>
              <doUpdate>false</doUpdate>
              <format>{0, number}</format>
              <items>
                <item>buildNumber</item>
              </items>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-plugin</artifactId>
            <executions>
              <execution>
                <phase>install</phase>
                <goals>
                  <goal>checkin</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <basedir>${basedir}</basedir>
              <includes>buildNumber.properties</includes>
              <message>[Automated checkin] of ${basedir} Build version: ${major.version}.${minor.version}.${buildNumber}</message>
              <developerConnectionUrl>...</developerConnectionUrl>
            </configuration> …
Run Code Online (Sandbox Code Playgroud)

versioning version-control build-process maven-2

58
推荐指数
3
解决办法
2万
查看次数

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

我对 Jenkins 的输出有点困惑。

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

mvn deploy -Pprofile1
Run Code Online (Sandbox Code Playgroud)

我所有的插件都会运行 4 次:

  • 父/pom.xml
  • 父/模块1/pom.xml
  • 父/module2/pom.xml
  • 父/module3/pom.xml

我需要:

  • first-maven-plugin:只在父 pom.xml 中运行一次
  • second-maven-plugin:为每个pom.xml运行

为什么:

  • first-maven-plugin: 将在阶段运行:初始化 --> 相当长的清理操作。不想这4次
  • second-maven-plugin: 将在 phase:package --> necesaary 中运行所有 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> …
Run Code Online (Sandbox Code Playgroud)

profile plugins module maven

5
推荐指数
2
解决办法
2264
查看次数