kotlin - 来自 Kotlin 的 Vert.x 服务代理与 vertx-codegen

标签 kotlin vert.x

我已经用 Kotlin 编写了一个 vertx 服务接口(interface),我正在尝试为其生成服务代理。但是,除了在 src/main 中生成 generate 目录之外,它什么也不做。

src/main/java/amb85/portfolio/package-info.java:

@ModuleGen(name = "portfolio", groupPackage = "amb85.portfolio")
package amb85.portfolio;

import io.vertx.codegen.annotations.ModuleGen;

然后我有以下服务接口(interface)src/main/kotlin/amb85/portfolio/PortfolioService.kt:

@VertxGen
@ProxyGen
interface PortfolioService {
    companion object {
        val ADDRESS = "service.portfolio"
        val EVENT_ADDRESS = "portfolio"
    }
    fun getPortfolio(resultHandler: (AsyncResult<Portfolio>) -> Unit)
    fun buy(amount: Int, quote: JsonObject, resultHandler: (AsyncResult<Portfolio>) -> Unit)
    fun sell(amount: Int, quote:JsonObject, resultHandler: (AsyncResult<Portfolio>) -> Unit)
    fun evaluate(resultHandler: (AsyncResult<Double>) -> Unit)
}

以及build.gradle中的相关配置:

task generateProxies(type: JavaCompile, group: "build",
        description: "Generates the Vert.x proxies") { // codegen
    source = sourceSets.main.java
    source += sourceSets.main.kotlin
    classpath = configurations.compile + configurations.compileOnly
    destinationDir = project.file("${projectDir}/src/main/generated")
    options.compilerArgs = [
            "-proc:only",
            "-processor", "io.vertx.codegen.CodeGenProcessor",
            "-Acodegen.output=${project.projectDir}/src/main"
    ]
}

然后,我运行 ./gradlew Portfolio:generateProxies,但除了 generate 目录之外,没有任何内容。

是否可以使用vertx-codegen基于Kotlin编写的接口(interface)生成服务代理?如果是这样,我缺少哪些配置步骤?如果没有,还有其他方法生成代理吗?更好的是,有没有一种方法可以完全在 Kotlin 中完成,避免 java 生成或将其用作中间步骤?

最佳答案

通过 kotlin 使用 vertx 服务代理的最简单方法是使用 kapt和 vertx-codegen processor 分类依赖项。

在您的 build.gradle 中,您应该添加以下内容:

apply plugin: 'kotlin-kapt'

dependencies {

    kapt "io.vertx:vertx-codegen:$vertx_version:processor"
    compileOnly "io.vertx:vertx-codegen:$vertx_version"

    // other deps go here
}

到目前为止还不需要其他任何东西。

关于kotlin - 来自 Kotlin 的 Vert.x 服务代理与 vertx-codegen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44781041/

相关文章:

java - 我需要从 Vert.x 的 SQLConnection 获取底层 java.sql.Connection

在 vertx 中使用身份验证的 Redis pubsub

postgresql - 在更新语句中排除空列 - JOOQ

android - 导航架构组件动画

Android Studio 不允许我使用 repeatOnLifecycle

redis - 3.7.0之后带有事件总线消费者的PubSub vertx redis

java - IllegalStateException in retryWhen with ReadStreamAdapter

kotlin - Kotlin 中的重载强制转换运算符

android - 使用接口(interface)而不是类定义 Retrofit 返回类型

来自 Vertx 和 AMQPBridge 的 Java 运行时警告