You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, can anybody provide kotlin version of this tutorial with service proxies? I couldn't manage it to work;
Every time I get such error on build:
build/tmp/kapt3/stubs/main/uz/craftier/database/WikiDatabaseService.java:46: error: Could not generate model for uz.craftier.database.WikiDatabaseService.Companion: @VertxGen can only be used with interfaces or enums in uz.craftier.database.WikiDatabaseService.Companion
I ran into the same issue when experimenting with service proxies.
The problematic part is the companion object, which trips up the annotation generator.
@rgmz , I've tried adding @JvmStatic like you did on Kotlin 1.3.21n and I still have this error ".Companion is not legal for use for a constant type in code generation"
@rgmz sorry, I wanted to look into it but I never found the time. With @vietj, we discussed in the past to try to find a solution that wasn't Kotlin specific but I didn't find anything so far
could not generate model for com.raghu.vertx3guide.wiki.step3.database.WikiDatabaseService#create(io.vertx.ext.asyncsql.AsyncSQLClient,java.util.HashMap<com.raghu.vertx3guide.wiki.step3.database.SqlQuery,java.lang.String>,io.vertx.core.Handler<io.vertx.core.AsyncResult<com.raghu.vertx3guide.wiki.step3.database.WikiDatabaseService>>): type java.util.HashMap<com.raghu.vertx3guide.wiki.step3.database.SqlQuery,java.lang.String> is not legal for use for a parameter in code generation
public static com.raghu.vertx3guide.wiki.step3.database.WikiDatabaseService create(@org.jetbrains.annotations.NotNull()
Reacted by Richard Gomez, Andreas Jacobsen, Luis Henrique Gomes Camilo, Jinzhou Tao, River, Dennis Dierkes, darius, Ruben Gees, Dang Fan, gadamore91 and 4 more
Is extension function a possible workaround? So that we won't need to setup companion object
Unfortunately Kotlin does not support static extension functions; in order to call create you'd need to already have an instance of WikiDatabaseServiceImpl.
Additionally, non-static methods are not picked up by codegen so you would need to manually define factory methods for everything, e.g. the rxified API.
Activity
abelhegedus commentedon Feb 28, 2018
I ran into the same issue when experimenting with service proxies.
The problematic part is the
companion object, which trips up the annotation generator.A possible workaround:
desmondtzq commentedon Jun 18, 2018
Is it also possible to generate the rx version of the proxy?
mustafakibar commentedon Jun 21, 2018
I have the same problem on rx version of the service proxy..
desdulianto commentedon Aug 7, 2018
I also get the same problem, and then based on @abelhegedus' idea, here my workaround:
I added
@GenIgnoreannotation oncompanion objectbecausekaptkeeps complaining aboutMap<SqlQuery, String>andJDBCClientare not legal types.rgmz commentedon Aug 9, 2018
@desmondtzq @mustafakibar To my knowledge there is no way to do this in 1.2.x as interfaces are not allowed to have
@JvmStaticmembers.However, support for this is added in 1.3 (https://youtrack.jetbrains.com/issue/KT-6301) meaning that the following should work:
(You can actually use this feature now, as per Michael Bogdanov's comment, though since it's pre-release it's technically not stable.)
raghumulukutla commentedon Mar 28, 2019
@rgmz , I've tried adding @JvmStatic like you did on Kotlin 1.3.21n and I still have this error ".Companion is not legal for use for a constant type in code generation"
Any other workarounds that you might suggest?
rgmz commentedon Mar 28, 2019
@raghumulukutla A change introduced in Vert.x 3.6.x inadvertently broke this.
I created a pull request to fix this—hopefully it makes it into the next release, or a viable workaround is provided.
@gmariotti do you have any suggested workarounds to mimic this behaviour?
gmariotti commentedon Mar 28, 2019
@rgmz sorry, I wanted to look into it but I never found the time. With @vietj, we discussed in the past to try to find a solution that wasn't Kotlin specific but I didn't find anything so far
raghumulukutla commentedon Mar 28, 2019
@gmariotti @rgmz Thanks! I've also tried using a Vertx version < 3.6.x. Reproduces the same error.
rgmz commentedon Mar 31, 2019
@raghumulukutla Can you provide a reproducer? I do not get the error in version 3.5.4.
Try this ad-hoc example: https://github.com/rgmz/vertx-kotlin-service-proxy
raghumulukutla commentedon Apr 2, 2019
@rgmz I'm sorry, I should correct myself. I do not get the same error. But I do get a kaptKotlin error. Here's the reproducer:
https://github.com/raghumulukutla/vertx-guide-kotlin/tree/service_proxy/src/main/kotlin/com/raghu/vertx3guide/wiki/step3/database
WikiDatabaseService.kt
Error:
liuandong commentedon Apr 9, 2019
just use java interface in kotlin project
rayfragment commentedon Dec 2, 2019
Is extension function a possible workaround? So that we won't need to setup companion object
rgmz commentedon Dec 6, 2019
Unfortunately Kotlin does not support static extension functions; in order to call
createyou'd need to already have an instance ofWikiDatabaseServiceImpl.Additionally, non-static methods are not picked up by codegen so you would need to manually define factory methods for everything, e.g. the rxified API.
rgmz commentedon May 31, 2021
FYI, once Vert.x 4.1.0 is released this issue should be resolved.
4.1.0 isn't released yet, but this is now updated to 4.1.0.CR2.