1

I want to have a Parent Maven project that has two files.

src/license/LICENSE.txt src/license/NOTICE.txt

When I build my main Project, that references it as a Parent POM, I want those files to be included in the produced JAR.

I know I can use...

<build>
    <resources>
        <resource>
            <targetPath>META-INF</targetPath>
            <directory>src/license</directory>
            <includes>
                <include>NOTICE.txt</include>
                <include>LICENSE.txt</include>
            </includes>
        </resource>
    </resources>    
</build>

But this will only work when the files are located in main Project, not when they are in the Parent project.

jeff porter
  • 6,560
  • 13
  • 65
  • 123
  • 1
    Possible duplicate of [Maven copy resources in multi module project](https://stackoverflow.com/questions/7544330/maven-copy-resources-in-multi-module-project) – dur Mar 24 '18 at 18:14

1 Answers1

1

I found a solution to this.

First, create a new repo to hold the items you want to be copied in.

The POM of this should contain this (GAV details are com.jeff:base-pom-license)...

<build>
    <plugins>
        <plugin>
            <artifactId>maven-remote-resources-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>**/*.txt</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

Then in your Base pom add this...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-remote-resources-plugin</artifactId>
            <version>1.5</version>
            <configuration>
                <resourceBundles>
                    <resourceBundle>com.jeff:base-pom-license:${project.version}</resourceBundle>
                </resourceBundles>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>       

This will cause the files you have in the new maven repo to be included in all the places that extend the base pom.

jeff porter
  • 6,560
  • 13
  • 65
  • 123