Reusing ant-snippets in multi-module maven build

2019-07-02 09:05发布

How can I reuse an ant snippet in multiple projects? Lets say I have the following in my root pom.xml:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>gen-index</id>
            <phase>package</phase>
            <configuration>
                <target>
                    ... some non-trivial ant stuff here ...
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        <execution>
    </executions>
</plugin>

How can I have this ant snippet executed for selected sub-projects? I've tried adding the <plugin>...</plugin> part above to <pluginManagement>..., but I can't figure out how to specify for which sub-projects the ant snippet should be run.

标签: maven ant
1条回答
ゆ 、 Hurt°
2楼-- · 2019-07-02 09:49

i assume that your plugin definition with your target implementation is inside a pluginManagement section of a parent pom.xml

your ant target is inside a execution identified by "gen-index". it should be work if you declare some thing like this in your child project (but this time not inside a pluginManagement section...!!!):

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>gen-index</id>
                <execution>
            </executions>
        </plugin>
    </plugins>
</build>

this executes the target inherited by the parent pom with the same identifiert.

i hope this works four you. i used this several times like this..

with this constellation you could have more than one inside the same plugin in your parent pom.xml.

I have created a GitHub repository with a working example: https://github.com/StefanHeimberg/stackoverflow-16056194

查看更多
登录 后发表回答