3

I'm currently creating a parent POM, with all necessary configuration, as a base for all my personal projects. The ultimate goal is to have small child projects (= with little configuration) and to bootstrap projects more easily, by just inheriting the parent POM.

But I'm facing issues with plugins needing external files for configuration (as the maven-assembly-plugin, shown below in my example). I would like to have only one external file (the descriptor file for maven-assembly-plugin) shared across all child projects, and not redefine the same file in all my child projects.

Here's a complete example.

Example with maven-assembly-plugin

My parent POM (my-group-id:parent:1.0.0:pom), defining a configuration for maven-assembly-plugin, is the following:

<project>
  <groupId>my-group-id</groupId>
  <artifactId>parent</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <build>
    <pluginManagement>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>create-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>src/assembly/bin.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </pluginManagement>
  </build>
</project>

If I want all child projects to have the maven-assembly-plugin configuration defined in the parent, I must write the following (example for child project child1) :

<project>
  <parent>
    <groupId>my-group-id</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0</version>
  </parent>
  <artifactId>child1</artifactId>
  <version>0.0.1</version>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

But, as I said in introduction : with that configuration, for each child, I have to create a descriptor file (src/assembly/bin.xml) in its own project.

Moreover, it turns out that all my child projects have the same bin.xml file. I'll save you the contents, but for information, packaging is always a .tar.gz archive, with external libraries separated in a lib folder.

I just want to inherit the parent POM without bothering about the way assembly is done in my child projects. A shared descriptor file (bin.xml) seems to be the solution, but I can't see how to share it across all child projects. Anyway, I don't want to have a bin.xml per child project.

The question could be extended and does not only address the configuration of maven-assembly-plugin, because there is other plugins configurable with external files (docker-maven-plugin for example, where a Dockerfile can be provided). But at least, finding a solution for the maven-assembly-plugin specific case will be really helpful!

norbjd
  • 10,166
  • 4
  • 45
  • 80
  • 2
    I recommend to read the [shared assembly descriptor](https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html) cause it sounds as this is your problem. – khmarbaise Sep 15 '18 at 10:37
  • 1
    Thanks, that's exactly what I was looking for `maven-assembly-plugin`! However, as I explained (last paragraph), this was just a facet of my question : I'm wondering if there is a generic solution to share resources (not only assembly descriptors, but other stuff like shell scripts, files, ...) across projects. – norbjd Sep 15 '18 at 10:59
  • 3
    Take a look at [maven-remote-resouces-plugin](http://maven.apache.org/plugins/maven-remote-resources-plugin/)...But it depends on your use case... – khmarbaise Sep 15 '18 at 11:32
  • I did not know this plugin, and indeed it provides a generic solution to share resources between projects. Thanks for the help! – norbjd Sep 15 '18 at 16:40

0 Answers0