Spring 引导 Maven 插件包含资源

Spring Boot Maven Plugin Include Resources

例子

是否有可能以某种方式配置 spring boot maven 插件以包含来自依赖项的资源。

例如如果在我的 spring 引导项目中我有:

  <dependency>
    <groupId>co.company</groupId>
    <artifactId>example</artifactId>
  </dependency>

并且在该 JAR 文件中有一个属性文件,例如 example.properties

jar -tf example.jar | grep example.properties | wc -l

结果为 1。

但是,当我构建 spring 引导 JAR 时,此属性文件未添加到 src/main/resources。包含它的 JAR 包含在 BOOT-INF/lib/example.jar

但是,就我而言。我想将 src/main/resources 的内容提取到 spring 引导 JAR 的引导 BOOT-INF/classes/ 目录中,以便自动配置之类的东西可以提取它。

现实世界

在现实世界中,我正在尝试使用:

我认为这个问题的解决方案与 非常相似。

您可以在 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/BOOT-INF/</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

这会将资源从 module-a 复制到 boot-moduleBOOT-INF 目录。我在 GitHub.

上发布了一个更完整的示例