从 Maven 中的命令行参数中跳过 exec-maven-plugin

问题描述 投票:0回答:3

在我的项目POM中默认会执行

exec-maven-plugin, rpm-maven-plugin
, 这在本地编译/构建中不是必需的。

我想通过传递命令行参数来跳过这些插件执行 我尝试使用下面的命令像普通插件一样跳过它们,但没有成功!

mvn install -Dmaven.test.skip=true -Dmaven.exec.skip=true -Dmaven.rpm.skip=true

maven plugins execution skip
3个回答
33
投票

更新:从版本1.4.0开始,原名称

skip
已更改为
exec.skip

这个page应该告诉您cmdline要传递的参数名称(即用户属性)被称为

skip
,这是一个选择不当的名称。要解决此问题,您可以执行以下操作:

<properties>
  <maven.exec.skip>false</maven.exec.skip> <!-- default -->
</properties>
...
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.3.2</version>
  <configuration>
    <skip>${maven.exec.skip}</skip>
  </configuration>
</plugin>

15
投票

4
投票

使用配置文件(尽可能少)和执行阶段,您可以实现您想要的不处理跳过属性的插件:

插件配置:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>rpm-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>${rpmPackagePhase}</phase>
            <id>generate-rpm</id>
            <goals>
                <goal>rpm</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
    ...
    </configuration>
</plugin>

配置文件配置:

<profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <rpmPackagePhase>none</rpmPackagePhase>
        </properties>
    </profile>
    <profile>
        <id>rpmPackage</id>
        <activation>
            <property>
                <name>rpm.package</name>
                <value>true</value>
            </property>
        </activation>
        <properties>
            <rpmPackagePhase>package</rpmPackagePhase>
        </properties>
    </profile>
</profiles>

调用:

mvn package -Drpm.package=true [...]
© www.soinside.com 2019 - 2024. All rights reserved.