首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在gradle多项目中使用带有spring-boot-configuration-processor的kapt

在gradle多项目中使用带有spring-boot-configuration-processor的kapt
EN

Stack Overflow用户
提问于 2020-10-15 19:10:12
回答 2查看 881关注 0票数 0

我试图在spring boot和kotlin中创建一个gradle多项目。使用gradle kotlin脚本编写构建文件。这是我的根项目的构建文件(build.gradle.kts)。

代码语言:javascript
复制
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)时,我得到了这个错误:

代码语言:javascript
复制
> 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中是这样声明的。

代码语言:javascript
复制
include("adapters:drivers:web")

PS:如果我使用annotationprocessor代替kapt,构建就会成功。但我不确定annotationprocessor是否可以与kapt互换使用,因为这将是一个kotlin项目。

EN

回答 2

Stack Overflow用户

发布于 2021-03-02 02:07:50

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

似乎kapt不受依赖项版本管理..

票数 0
EN

Stack Overflow用户

发布于 2022-02-02 09:44:23

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

代码语言:javascript
复制
subprojects {
   ...
   repositories {
       mavenCentral()
   }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64370286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档