Maven Additional-spring-configuration-metadata.json仅在第二次构建时与configurationProperties生成的元数据合并
我有一个kotlin spring boot自动配置项目。它有一个用Maven Additional-spring-configuration-metadata.json仅在第二次构建时与configurationProperties生成的元数据合并,maven,spring-boot,kotlin,kapt,Maven,Spring Boot,Kotlin,Kapt,我有一个kotlin spring boot自动配置项目。它有一个用@ConfigurationProperties注释的类。这将按预期生成属性元数据文件。我想添加一个不来自@ConfigurationProperties类的属性。如文档所述,要做到这一点,我应该创建自己的附加spring配置元数据.json文件 我发现第一次运行mvn clean package时,生成的元数据没有包含来自附加spring配置元数据.json的信息。第二次运行mvn包时(假设我没有进行清理),元数据包含来自ad
@ConfigurationProperties
注释的类。这将按预期生成属性元数据文件。我想添加一个不来自@ConfigurationProperties
类的属性。如文档所述,要做到这一点,我应该创建自己的附加spring配置元数据.json
文件
我发现第一次运行mvn clean package时,生成的元数据没有包含来自附加spring配置元数据.json
的信息。第二次运行mvn包时(假设我没有进行清理),元数据包含来自additional spring configuration metadata.json的信息
为什么会这样?我如何修复它以每次第一次生成数据
我的pom如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.redacted.entity.autoconfigure</groupId>
<artifactId>mongo-autoconfiguration</artifactId>
<version>1.0.0</version>
<name>mongo-autoconfiguration</name>
<description>AutoConfiguration for mongo</description>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.3.50</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<version>2.1.7.RELEASE</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.1.7.RELEASE</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
4.0.0
org.springframework.boot
spring启动程序父级
2.1.7.发布
com.redact.entity.autoconfigure
mongo自动配置
1.0.0
mongo自动配置
mongo的自动配置
1.8
1.3.50
org.springframework.boot
弹簧靴自动配置
org.springframework.boot
spring引导自动配置处理器
真的
org.springframework.boot
spring引导配置处理器
真的
org.jetbrains.kotlin
科特林反射
org.jetbrains.kotlin
kotlin-stdlib-jdk8
${project.basedir}/src/main/kotlin
${project.basedir}/src/test/kotlin
org.jetbrains.kotlin
kotlin maven插件
卡普特
卡普特
src/main/kotlin
org.springframework.boot
spring引导自动配置处理器
2.1.7.发布
org.springframework.boot
spring引导配置处理器
2.1.7.发布
编译
编译
-Xjsr305=严格
春天
org.jetbrains.kotlin
科特林·马文·阿洛彭
${kotlin.version}
更新:我在下面添加了一个解决方案,但我仍然有悬赏悬赏。如果有人找到一种解决问题的不那么麻烦的方法,我会奖励你,因为你可能遇到了一个kapt目标没有实现的bug-。尽管这被标记为已修复,但最近也有其他报告的评论存在相同的问题。我通过添加mvn copy resources插件来修复它,以便在process sources阶段复制附加的spring configuration metadata.json文件,以便在kapt运行时可用
附加-spring-configuration-metadata.json
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/META-INF</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<includes>
<include>
additional-spring-configuration-metadata.json
</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
maven资源插件
3.1.0
复制资源
过程源
复制资源
${basedir}/target/classes/META-INF
src/main/resources/META-INF
附加-spring-configuration-metadata.json
我尝试删除了all open dependency和spring编译器插件,但它仍然不起作用,所以我猜它与此bug无关