Search code examples
mavenspring-bootspring-boot-maven-plugin

How Can One Include Resources From Another Module In A Spring Boot Maven Multi Module Project


I have a spring boot mavel multi-module project.

If the spring boot module depends on module A and in the src/main/resources folder of module A there is a properties file or some other resource that I want bundled in the final spring boot app, how can I achieve this.

Currently, if I run jar -tf on the module A JAR it includes the file:

jar -tf module-a/target/module-a-0.0.1-SNAPSHOT.jar | grep changelog

db/changelog/
db/changelog/db.changelog-master.yaml

However:

jar -tf boot-module/target/boot-module-0.0.1-SNAPSHOT.jar | grep changelog | wc -l
       0

Thanks in advance for any advice.


Solution

  • If I understand your requirements correctly, I believe you can use the unpack goal of the maven-dependency-plugin in your Spring Boot module:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>module-a</artifactId>
                            <version>${project.version}</version>
                            <includes>**/*.yaml</includes>
                        </artifactItem>
                    </artifactItems>
                    <outputDirectory>${project.build.directory}/classes/</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    That will copy the resources from module-a to boot-module. I've posted a complete example on GitHub.