【问题标题】:Is it possible to run a plugin in between two executions of another plugin?是否可以在另一个插件的两次执行之间运行一个插件?
【发布时间】:2021-08-20 09:14:17
【问题描述】:

出于解释目的,假设我想:

  • 复制项目工件 jar (maven-antrun-plugin)
  • 复制依赖项(maven-dependency-plugin)
  • 编译安装程序(maven-antrun-plugin)

不幸的是,两个 maven-antrun-plugin 执行是一起运行的。有关于重复插件声明的警告,它们在有效的 POM 中合并在一起。

编辑: 这个特定任务可以通过使用其他阶段或 install4j 插件来解决,但我感兴趣的是它是否通常可以执行,例如maven-antrun-plugin 在同一阶段以特定顺序多次(中间有其他插件)。

  <build>
    <plugins>

      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <!-- copy project jar -->
      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>copy-project-jar</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <copy file="target/${project.artifactId}-${project.version}.jar"
                  tofile="target/installer/bin/${project.artifactId}.jar" />
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <!-- copy dependencies -->
      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/installer/bin</outputDirectory>
              <stripVersion>true</stripVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <!-- compile installer -->
      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>compile-installer</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <exec executable="${install4j.home}/bin/install4jc.exe">
                  <arg value="installer.install4j" />
                </exec>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

合并的有效 POM:

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>copy-project-artifact</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <copy file="target/test-1.0.0.jar" tofile="target/installer/bin/test.jar" />
              </target>
            </configuration>
          </execution>
          <execution>
            <id>compile-installer</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <exec executable="C:\Program Files\install4j8/bin/install4jc.exe">
                  <arg value="installer.install4j" />
                </exec>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

【问题讨论】:

  • 也许我弄错了,但为什么不使用 maven 插件? ej-technologies.com/resources/install4j/help/doc/cli/maven.html
  • @khmarbaise 是的,install4j 插件可用于此特定任务。但它更多地是作为一个例子来解释我的问题
  • 让插件运行的唯一方法是将该插件绑定到不同的生命周期阶段...

标签: maven maven-3 maven-antrun-plugin


【解决方案1】:

首先,你需要把所有的执行放到同一个插件定义中。

其次,我怀疑这是可能的,但通常您可以通过使用更多阶段来拆分。例如。您可以使用prepare-package 来首次执行antrun 插件。

【讨论】:

  • 是的,我知道在给定的示例中使用其他阶段是如何工作的。
猜你喜欢
  • 2016-09-22
  • 2012-11-04
  • 2016-02-27
  • 2020-12-20
  • 1970-01-01
  • 1970-01-01
  • 2010-11-30
  • 1970-01-01
相关资源
最近更新 更多