Reputation: 1463
I've written a vertx service interface in Kotlin, for which I am trying to generate service proxies. However, apart from generating the generated
directory in src/main
, it does nothing.
src/main/java/amb85/portfolio/package-info.java
:
@ModuleGen(name = "portfolio", groupPackage = "amb85.portfolio")
package amb85.portfolio;
import io.vertx.codegen.annotations.ModuleGen;
I then have the following service 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)
}
And the relevant configuration from 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"
]
}
I then run ./gradlew portfolio:generateProxies
, but nothing beyond the generated
directory.
Is it possible to use vertx-codegen
to generate service proxies based on an interface written in Kotlin? If so, what configuration steps am I missing? If not, is there any other way to generate the proxies? Even better, is there a way to do it entirely in Kotlin, avoiding the java generation or using it as an intermediate step?
Upvotes: 2
Views: 2257
Reputation: 25
Add the service proxy procesor in order to generate the proxy.
kapt "io.vertx:vertx-codegen:$vertxVersion:processor"
kapt "io.vertx:vertx-service-proxy:$vertxVersion:processor"
compile "io.vertx:vertx-service-proxy:$vertxVersion"
And if you are going to generate the service with @VertxGen you should use the package-info.java even if you are writing Kotlin:
@ModuleGen(name = "example", groupPackage = "com.some")
package com.something;
import io.vertx.codegen.annotations.ModuleGen;
Upvotes: 1
Reputation: 3268
The easiest way to use vertx service proxies with kotlin
is to use kapt and vertx-codegen processor
classified dependency.
In your build.gradle
you should add following:
apply plugin: 'kotlin-kapt'
dependencies {
kapt "io.vertx:vertx-codegen:$vertx_version:processor"
compileOnly "io.vertx:vertx-codegen:$vertx_version"
// other deps go here
}
Nothing else needed so far.
Upvotes: 7
Reputation: 3753
You should probably define a source set for generated
. I have a separate Gradle script gradle/vertx-codegen.gradle
that I include where needed, and that works fine (its only for Java, so you should adapt it a bit):
sourceSets {
generated{
java.srcDir "${projectDir}/src/generated/java"
}
}
task generateProxies(type: JavaCompile) {
group = "build"
description = "Generate Vert.x service proxies"
source = sourceSets.main.java
classpath = configurations.compile
options.compilerArgs = [
"-proc:only",
"-processor", "io.vertx.codegen.CodeGenProcessor",
"-AoutputDirectory=${projectDir}/src/main"
]
destinationDir = file("${projectDir}/src/generated/java")
}
compileJava{
dependsOn generateProxies
source += sourceSets.generated.java
}
clean {
delete += sourceSets.generated.java.srcDirs
}
Hope this helps!
Upvotes: 0