如何在 Spring Boot Maven 多模块项目中包含来自另一个模块的资源

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

我有一个spring boot mavel 多模块项目。

如果 spring 引导模块依赖于模块 A 并且在模块 Asrc/main/resources 文件夹中有一个我想要的属性文件或其他资源捆绑在最终的 spring 启动应用程序中,我该如何实现。

目前,如果我 运行 jar -tf 在模块 A JAR 上,它包含文件:

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

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

但是:

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

提前感谢您的任何建议。

如果我正确理解了您的要求,我相信您可以在 Spring 引导模块中使用 maven-dependency-pluginunpack 目标:

<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>

这会将资源从 module-a 复制到 boot-module。我已经在 GitHub.

上发布了一个完整的示例