首页 文章

kapt插件没有使用gradle-script-kotlin

提问于
浏览
0

我想将基于vertx的项目移动到https://github.com/sczyh30/vertx-blueprint-microservice.git模板 . 蓝图项目使用注释@vertxGen等在编译期间生成代码 .

我正在使用gradle-script-kotlin来构建项目 . 我需要使用kapt插件根据注释生成代码(通过vertx ... codegen) . 不幸的是,我无法正确配置kapt插件 . 它给出了以下错误:

w: [kapt] Sources output directory is not specified, skipping annotation processing

如果有人能修复我的gradle构建文件,我会很高兴 . 以下是与kapt相关的片段

import org.jetbrains.kotlin.gradle.plugin.* // kaptExtension
...
apply {
  plugin("kotlin-kapt")
}
...

fun Project.kapt(setup: KaptExtension.() -> Unit) = the<KaptExtension>().setup()

kapt {
        generateStubs = true

        javacOptions( closureOf<KaptJavacOptionsDelegate> {
                option("-proc:only")
                option("-processor", "io.vertx.codegen.CodeGenProcessor") // vertx processor here
                option("-AoutputDirectory", "${projectDir}/src/main")
                option("-Acodegen.output", "${projectDir}/src/main")
        } )

        // specify output of generated code
        arguments( closureOf<KaptAnnotationProcessorOptions> {
                arg("destinationDir", "${buildDir}/generated/source/kapt/main")
        } )
}
...
java {
...
        sourceSets.getByName("main").java.srcDirs("${project.buildDir}/generated/source/kapt/main")
}

让我知道任何其他信息/查询 . 提前致谢 .

2 回答

  • 0

    我不得不在build.gradle.kts中添加以下内容

    dependencies {
    ....
            kapt("io.vertx:vertx-codegen:$vertx_version:processor")
    ...
    }
    

    仍然不知道为什么 . 张贴在这里让其他人知道 .

  • 0

    除了kotlin-kapt插件和其他kotlin依赖项之外,还要在build.gradle文件中保留以下依赖项 . 生成代码就足够了(我使用相同的方式) . 除非您正在寻找一些自定义,否则不需要上面提到的kapt和java块 .

    dependencies {
      kapt "io.vertx:vertx-codegen:$vertxVersion:processor"
      compileOnly "io.vertx:vertx-codegen:$vertxVersion"
    }
    

相关问题