Reusing ant-snippets in multi-module maven build

♀尐吖头ヾ 提交于 2019-12-13 14:06:50

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/16056194/reusing-ant-snippets-in-multi-module-maven-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!