Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge additional-spring-configuration-metadata.json with kapt when using Kotlin and Gradle?

I have read these documents but I don’t know how to merge additional-spring-configuration-metadata.json with kapt when using Kotlin and Gradle.
https://docs.spring.io/spring-boot/docs/2.2.x/reference/html/appendix-configuration-metadata.html#configuration-metadata-annotation-processor
https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-kotlin-configuration-properties

I managed to merge it this way, but I want to know the official way.

plugins {
    id("org.springframework.boot") version "2.2.2.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    kotlin("jvm") version "1.3.61"
    kotlin("plugin.spring") version "1.3.61"
    kotlin("kapt") version "1.3.61"
}

dependencies {
    kapt("org.springframework.boot:spring-boot-configuration-processor")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    …
}

kapt {
    arguments {
        arg(
            "org.springframework.boot.configurationprocessor.additionalMetadataLocations",
            "$projectDir/src/main/resources"
        )
    }
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}
like image 218
hirakida Avatar asked Oct 20 '25 13:10

hirakida


1 Answers

Adding an answer here for better visibility. This is a known issue in the Kapt maven plugin that does not make sure the compilation classpath is available when the annotation processor runs. The implementation can't see the file and therefore won't merge it.

Your workaround works and there is an issue you can vote for in the JetBrains issue tracker.

like image 92
Stephane Nicoll Avatar answered Oct 23 '25 08:10

Stephane Nicoll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!