user1064504
user1064504

Reputation: 593

Unable to run basic declarative jdbi3 in kotlin in existing java gradle project

I am new to kotlin, my basic build.gralde is as follows in an existing java + gradle project.

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.7.20"
}

dependencies {
    implementation("org.postgresql:postgresql")
    implementation("org.jdbi:jdbi3-kotlin")
    implementation("org.jdbi:jdbi3-kotlin-sqlobject")

    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
}

All kotlin dependancies are using version 1.7.20.

My super basic kotlin is as follows. I've simple data class Org for holding the row values, a Simple RowMapper. I hit same issue even if i use RowMapper or not.

data class Org(val name: String)
class OrgRowMapper: RowMapper<Org> {
    override fun map(rs: ResultSet, ctx: StatementContext): Org {
        return Org(rs.getString("name"))
    }
}

interface OrgDao {
    @SqlQuery("SELECT * FROM organization")
    @RegisterKotlinMapper(OrgRowMapper::class) // with or without rowMapper
    fun listOrg(): List<Org>
}

fun jdbi(): Jdbi {
    val jdbi = Jdbi.create("jdbc:postgresql://...")
    jdbi.installPlugin(KotlinPlugin())
    jdbi.installPlugin(KotlinSqlObjectPlugin())
    return jdbi
}

fun trySomeOrg(jdbi: Jdbi) {
    val orgDao = jdbi.onDemand<OrgDao>()
    val orgs = orgDao.listOrg()
    println(orgs)
}

fun main() {
    val jdbi = jdbi()
    trySomeOrg(jdbi)
}

However list call is throwing MethodNotFound exception

Exception in thread "main" java.lang.NoSuchMethodError: 'java.util.Map kotlin.collections.MapsKt.createMapBuilder()'
    at kotlin.reflect.jvm.internal.impl.descriptors.Visibilities.<clinit>(Visibilities.kt:56)

if I avoid RegisterRowMapper, I get hit by

Exception in thread "main" java.lang.NoSuchMethodError: 'void kotlin.jvm.internal.PropertyReference1Impl.<init>(java.lang.Class, java.lang.String, java.lang.String, int)'

I believe this has something to do with kotlin-java lambda extensions. If I lift and shift this code in a brand new kotlin only project in IntelliJ, it works.

Update:

It seems like an issue with kotlin-reflect, I tried following

fun main() {
    println("Hello World")
    println(A::p.javaGetter) // prints "public final int A.getP()"
    println(A::p.javaField)  // prints "private final int A.p"
}

in mix kotlin+java project, this throws.

Exception in thread "main" java.lang.NoSuchMethodError: 'void kotlin.jvm.internal.PropertyReference1Impl.<init>(java.lang.Class, java.lang.String, java.lang.String, int)'

However works correctly in kotlin only project.

I verified gradle dependencies, kotlin-reflect:1.7.20 is listed under runtimeClassPath

runtimeClasspath - Runtime classpath of compilation 'main' (target  (jvm)).
+--- org.slf4j:slf4j-api -> 2.0.3
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20
|    |    \--- org.jetbrains:annotations:13.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20
|         \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
+--- ch.qos.logback:logback-core -> 1.2.11
+--- ch.qos.logback:logback-classic -> 1.2.11
|    +--- ch.qos.logback:logback-core:1.2.11
|    \--- org.slf4j:slf4j-api:1.7.32 -> 2.0.3
+--- javax.annotation:javax.annotation-api -> 1.3.2
+--- com.newrelic.logging:logback -> 2.5.0
|    +--- com.fasterxml.jackson.core:jackson-core:2.11.1 -> 2.13.4
|    |    \--- com.fasterxml.jackson:jackson-bom:2.13.4
|    |         \--- com.fasterxml.jackson.core:jackson-core:2.13.4 (c)
|    +--- ch.qos.logback:logback-core:1.2.0 -> 1.2.11
|    +--- ch.qos.logback:logback-classic:1.2.0 -> 1.2.11 (*)
|    +--- com.newrelic.telemetry:telemetry-core:0.13.2
|    |    \--- org.slf4j:slf4j-api:1.7.30 -> 2.0.3
|    \--- com.newrelic.agent.java:newrelic-api:7.6.0 -> 7.10.0
+--- org.jacoco:org.jacoco.ant -> 0.8.8
|    +--- org.jacoco:org.jacoco.core:0.8.8
|    |    +--- org.ow2.asm:asm:9.2
|    |    +--- org.ow2.asm:asm-commons:9.2
|    |    |    +--- org.ow2.asm:asm:9.2
|    |    |    +--- org.ow2.asm:asm-tree:9.2
|    |    |    |    \--- org.ow2.asm:asm:9.2
|    |    |    \--- org.ow2.asm:asm-analysis:9.2
|    |    |         \--- org.ow2.asm:asm-tree:9.2 (*)
|    |    \--- org.ow2.asm:asm-tree:9.2 (*)
|    +--- org.jacoco:org.jacoco.report:0.8.8
|    |    \--- org.jacoco:org.jacoco.core:0.8.8 (*)
|    \--- org.jacoco:org.jacoco.agent:0.8.8
+--- org.jetbrains.kotlin:kotlin-reflect:1.7.20
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
+--- org.slf4j:slf4j-api:{strictly 2.0.3} -> 2.0.3 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{strictly 1.7.20} -> 1.7.20 (c)
+--- ch.qos.logback:logback-core:{strictly 1.2.11} -> 1.2.11 (c)
+--- ch.qos.logback:logback-classic:{strictly 1.2.11} -> 1.2.11 (c)
+--- javax.annotation:javax.annotation-api:{strictly 1.3.2} -> 1.3.2 (c)
+--- com.newrelic.logging:logback:{strictly 2.5.0} -> 2.5.0 (c)
+--- org.jacoco:org.jacoco.ant:{strictly 0.8.8} -> 0.8.8 (c)
+--- org.jetbrains.kotlin:kotlin-reflect:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jacoco:org.jacoco.core:{strictly 0.8.8} -> 0.8.8 (c)
+--- org.jacoco:org.jacoco.report:{strictly 0.8.8} -> 0.8.8 (c)
+--- org.jacoco:org.jacoco.agent:{strictly 0.8.8} -> 0.8.8 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-common:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jetbrains:annotations:{strictly 13.0} -> 13.0 (c)
+--- org.ow2.asm:asm:{strictly 9.2} -> 9.2 (c)
+--- org.ow2.asm:asm-commons:{strictly 9.2} -> 9.2 (c)
+--- org.ow2.asm:asm-tree:{strictly 9.2} -> 9.2 (c)
\--- org.ow2.asm:asm-analysis:{strictly 9.2} -> 9.2 (c)

Upvotes: 0

Views: 244

Answers (0)

Related Questions