Use kapt with spring-boot-configuration-processor in a gradle multi project

3.3k views Asked by At

I am trying to create a gradle multi project in spring boot and kotlin. Using gradle kotlin scripts to write build file. This is my root project's build file (build.gradle.kts).

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    val kotlinVersion = "1.4.10"
    val springBootVersion = "2.3.4.RELEASE"
    val springDependencyManagementVersion = "1.0.10.RELEASE"


    id("org.springframework.boot") version springBootVersion apply false
    id("io.spring.dependency-management") version springDependencyManagementVersion apply false
    kotlin("jvm") version kotlinVersion
    kotlin("kapt") version kotlinVersion
    kotlin("plugin.spring") version kotlinVersion apply false
}

allprojects {
    repositories {
        jcenter()
    }

    group = "org.example"
    version = "1.0-SNAPSHOT"
}

subprojects {
    apply {
        plugin("org.jetbrains.kotlin.jvm")
        plugin("org.jetbrains.kotlin.kapt")
        plugin("org.jetbrains.kotlin.plugin.spring")
    }
    configure<JavaPluginExtension> {
        sourceCompatibility = JavaVersion.VERSION_11
    }


    val developmentOnly by configurations.creating
    configurations.runtimeClasspath.get().extendsFrom(developmentOnly)
    dependencies {
        implementation("org.springframework.boot:spring-boot-starter-web")
        api(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
        implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
        implementation("org.jetbrains.kotlin:kotlin-reflect")
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
        developmentOnly("org.springframework.boot:spring-boot-devtools")
        kapt("org.springframework.boot:spring-boot-configuration-processor")
        testImplementation("org.springframework.boot:spring-boot-starter-test") {
            exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
        }
    }
}

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "11"
    }
}

When building (./gradlew build) I'm getting this error:

> Task :adapters:kaptKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':adapters:kaptKotlin'.
> Could not resolve all files for configuration ':adapters:kapt'.
   > Could not find org.springframework.boot:spring-boot-configuration-processor:.
     Required by:
         project :adapters

adapters:drivers:web is one of my subprojects and it is declared in settings.gradle.kts like this.

include("adapters:drivers:web")

PS: If I use annotationprocessor in place of kapt the build is successful. But I'm not sure if annotationprocessor can be used interchangeably with kapt since this will be a kotlin project.

2

There are 2 answers

0
FredSuvn On

kapt("org.springframework.boot:spring-boot-configuration-processor:$springBootVersion")

It seems kapt doesn't under the dependencies version management..

0
slorinc On

There is no repositories{} section is defined for you subprojects.

subprojects {
   ...
   repositories {
       mavenCentral()
   }
}