How to inherit from a multimodule Maven project with all its goodies?

落花浮王杯 提交于 2019-12-05 04:21:30

Now you can use the maven-tiles plugin to get the desired behaviour.

With maven-tiles you can define build behaviours in different poms and import them wherever you like.

There's a working sample attached to MNG-5102 --> daddy3.zip

Maven's inheritance-only strait jacket is now officially removed.

In my opinion, you could create multiple different assembly descriptors for this and configure multiple plugin executions with each execution referring to different descriptor. You will have to maintain your project as a single module instead of multi module project. Provided your distributions contain same set of classes but different resources or libraries, it could work.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <id>assembly</id>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                                <descriptor>one.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
                <execution>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <id>assembly</id>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                                <descriptor>two.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
                <execution>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <id>assembly</id>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                                                      <descriptor>three.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>

You could create a parent pom with assembly pluing configured there so that you can control the number of distributions and the change in packaging from there. Your projects will not need to know about details of different packaging.

I will strongly recommend to keep native libraries as separate module and use repository mechanism to install the compiled libraries into it. You can use different classifiers to segregate the platforms like,

mylib-2.0.0-win32_x86.dll
mylib-2.0.0-linux_x86.so
mylib-2.0.0-linux_x86_64.so

You can then reference to these libraries as dependencies in your project and then be able to package them along with your distribution.

The overall solution will greatly depend on how various distributions will differ and the overall process of packaging the distribution but I think this will work.

The ultimate and more scalable solution is to create your own packaging by implementing a Maven Plugin.

In my experience option 3 has worked the best, but I haven't had to scale it like you need to- when I've had to do that I've used the maven-ant-plugin to create a parameterized ant script to do the customization. It has some downsides- namely working with both ant and maven so the actual POM is more difficult to comprehend but it does allow for more flexibility than is otherwise possible with maven.

Tony Lâmpada

If you are using maven 3, you can define profiles the parent pom and activate them base on file existance. On the child modules you can "inherit flavours" by simply creating empty files.

This is better documented on the links below:

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