【问题标题】:Use kapt with spring-boot-configuration-processor in a gradle multi project在 gradle 多项目中使用 kapt 和 spring-boot-configuration-processor
【发布时间】:2020-10-15 11:10:11
【问题描述】:

我正在尝试在 spring boot 和 kotlin 中创建一个 gradle 多项目。使用 gradle kotlin 脚本编写构建文件。这是我的根项目的构建文件 (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"
    }
}

在构建 (./gradlew build) 时出现此错误:

> 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 是我的子项目之一,它在 settings.gradle.kts 中声明如下。

include("adapters:drivers:web")

PS:如果我使用注释处理器代替 kapt,则构建成功。但我不确定注解处理器是否可以与 kapt 互换使用,因为这将是一个 kotlin 项目。

【问题讨论】:

    标签: spring spring-boot kotlin gradle kapt


    【解决方案1】:

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

    似乎 kapt 不在依赖版本管理下..

    【讨论】:

      【解决方案2】:

      没有为您的子项目定义存储库{}部分。

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

      【讨论】:

        猜你喜欢
        • 2019-10-07
        • 2020-04-19
        • 2020-04-13
        • 2019-08-15
        • 2017-04-12
        • 1970-01-01
        • 2018-07-24
        • 2023-03-17
        • 2018-09-29
        相关资源
        最近更新 更多