【问题标题】:Disabling goals in a maven plugin execution在 Maven 插件执行中禁用目标
【发布时间】:2018-08-17 09:31:09
【问题描述】:

我有一个设置,我的大多数项目都需要运行 xtend 插件来实现 compile 和 testCompile 目标。我在 pluginManagement 部分描述它:

<plugin>
    <groupId>org.eclipse.xtend</groupId>
    <artifactId>xtend-maven-plugin</artifactId>
    <version>2.5.3</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

现在,有些项目不需要一个或另一个目标。我试过继承标签,玩弄随机属性,但没有奏效。如何覆盖执行以仅包含所需的目标?

更新:故事的结论是个人目标不能被禁用。可以管理的最小范围是execution

【问题讨论】:

    标签: java maven plugins


    【解决方案1】:

    一般来说,你只能通过一个技巧来禁用执行:

    将执行阶段设置为不存在阶段 (dont-execute)。但是请注意,您必须使用两个不同的执行 ID 才能分别关闭两个目标:

    <plugin>
        <groupId>org.eclipse.xtend</groupId>
        <artifactId>xtend-maven-plugin</artifactId>
        <version>2.5.3</version>
        <executions>
            <execution>
                <id>xtend-compile</id>
                <goals>
                    <goal>compile</goal>
                    <goal>testCompile</goal>
                </goals>
            </execution>
            <execution>
                <id>xtend-testCompile</id>
                <goals>
                    <goal>testCompile</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    子模块:

    <plugin>
        <groupId>org.eclipse.xtend</groupId>
        <artifactId>xtend-maven-plugin</artifactId>
        <version>2.5.3</version>
        <executions>
            <execution>
                <id>xtend-testCompile</id>
                <phase>dont-execute</phase>
            </execution>
        </executions>
    </plugin>
    

    在您的具体情况下,您当然也可以在每次执行中使用skipXtend 配置属性来不跳过执行,而只是阻止插件执行任何操作:

    <plugin>
        <groupId>org.eclipse.xtend</groupId>
        <artifactId>xtend-maven-plugin</artifactId>
        <version>2.5.3</version>
        <executions>
            <execution>
                <id>xtend-testCompile</id>
                <configuration>
                    <skipXtend>xtend-testCompile</skipXtend>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

    • 您也可以将 dont-execute 替换为 none,这似乎更容易被 IntelliJ 理解,但没有记录
    猜你喜欢
    • 1970-01-01
    • 2019-07-09
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 2016-07-16
    • 1970-01-01
    相关资源
    最近更新 更多