Ech*_*Cow 7 kotlin vert.x kapt
我尝试使用kapt并vertx-Codegen生成我的服务。但输出路径是/build/generated/source/kapt/main/. 我要/src/main/generated/。
配置build.gradle.kts,我发现生成adoc到/src/main/generated/,但其他文件没有变化。
有 build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.30"
kotlin("kapt") version "1.3.30"
id("io.vertx.vertx-plugin") version "0.8.0"
}
val vertxVersion = "3.8.0"
// ......
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
dependencies {
// ....
implementation("io.vertx:vertx-codegen")
kapt("io.vertx:vertx-service-proxy:$vertxVersion:processor")
kapt("io.vertx:vertx-codegen:$vertxVersion:processor")
// ....
}
kapt{
arguments {
arg("codegen.output", project.file("src/main/generated").path)
arg("kapt.kotlin.generated", project.file("src/main/generated").path)
}
javacOptions {
option("-AoutputDirectory", project.file("src/main/generated").path)
option("-Acodegen.output", project.file("src/main/generated").path)
}
}
Run Code Online (Sandbox Code Playgroud)
我希望输出路径是/src/main/generated/,但实际输出路径是/build/generated/source/kapt/main/。你能帮助我吗...?
生成 Kotlin 源代码:
我设法使用javac参数解决了生成的 Kotlin 源代码的问题:
val generatedKotlinSources = project.file("src/main/generated").path
kapt {
javacOptions {
option("-Akapt.kotlin.generated=$generatedKotlinSources")
}
}
Run Code Online (Sandbox Code Playgroud)
(令人惊讶的option("-Akapt.kotlin.generated", generatedKotlinSources)是没有用。)
该解决方案使用 与注释处理器配合使用,如使用 Kotlin 进行注释处理processingEnv.options["kapt.kotlin.generated"]页面中所述。
生成 Java 源:
但是,在生成 Java 源时,注释处理器使用使用javac context初始化的Filer。使用Java注释处理器时,您可以使用javac参数覆盖此路径,但此值在Kapt to中被硬编码(请参见源代码)。-s dir "generated/source/kapt/$sourceSetName"
因此,更改生成的 Java 的输出目录似乎不可能。
(是的,"generated/source/kaptKotlin/$sourceSetName"也是硬编码的,但它被用作"kapt.kotlin.generated"选项的默认值。)
| 归档时间: |
|
| 查看次数: |
685 次 |
| 最近记录: |