https://kotlinlang.org logo
Title
r

rikusen0335

11/25/2019, 11:00 AM
Copy-pasta from #general Hello, I'm new to Kotlin, and I want to use Exposed with it, but I'm getting
java.lang.NoClassDefFoundError: org/jetbrains/exposed/sql/Database
. Does anyone know how this happen and a solution for this? Thanks. This project using Gradle, JVM.
m

marstran

11/25/2019, 11:02 AM
Hi, how is your exposed dependency set up in Gradle?
r

rikusen0335

11/25/2019, 11:05 AM
Thanks for replying. in
build.gradle
,
repositories {
    jcenter()
}
dependencies {
    compile "org.jetbrains.exposed:exposed:0.17.7"
    compile "org.xerial:sqlite-jdbc:3.21.0.1"
}
Not sure if it would solve your problem, but worth a try.
r

rikusen0335

11/25/2019, 11:16 AM
I'm sorry I tried that. like this. isn't worked:
repositories {
    jcenter()
}
dependencies {
    compile 'org.jetbrains.exposed:exposed-core:0.18.1'
    compile 'org.jetbrains.exposed:exposed-dao:0.18.1'
    compile 'org.jetbrains.exposed:exposed-jdbc:0.18.1'
    compile "org.xerial:sqlite-jdbc:3.21.0.1"
}
Well I got error when trying to do this code:
Database.connect("jdbc:sqlite:file:test?mode=memory&cache=shared", "org.sqlite.JDBC")
import doesn't matter
d

Douglas KN

11/25/2019, 11:33 AM
for your db path does it work if you use a file?
"jdbc:sqlite:test.sqlite"
m

marstran

11/25/2019, 11:38 AM
Could it be that you also have an older version of exposed on your classpath? Some version where
Database
doesn't exist.
You can use
gradle dependencies
do view your dependency tree.
r

rikusen0335

11/25/2019, 11:58 AM
@Douglas KN It doesn't work. I tested it on 1.18.1 and also 1.17.7.
@marstran Okay, let me try it
result output:
testRuntimeClasspath - Runtime classpath of compilation 'test' (target  (jvm)).
+--- org.jetbrains.exposed:exposed-core:0.18.1
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.60
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.60
|    |    \--- org.jetbrains:annotations:13.0
|    +--- org.jetbrains.kotlin:kotlin-reflect:1.3.50
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.60 (*)
|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M1
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.31 -> 1.3.60 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.31 -> 1.3.60
|    \--- org.slf4j:slf4j-api:1.7.25
+--- org.jetbrains.exposed:exposed-dao:0.18.1
|    \--- org.jetbrains.exposed:exposed-core:0.18.1 (*)
+--- org.jetbrains.exposed:exposed-jdbc:0.18.1
|    \--- org.jetbrains.exposed:exposed-core:0.18.1 (*)
+--- org.xerial:sqlite-jdbc:3.21.0.1
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.60 (*)
\--- junit:junit:4.12
     \--- org.hamcrest:hamcrest-core:1.3
d

Douglas KN

11/25/2019, 12:31 PM
@rikusen0335 do you need to include one of the time modules? exposed-jodatime or exposed-java-time
i

Igor Dzichkovskii

11/25/2019, 12:39 PM
You shouldn’t repeat the libraries in dependencies and isn’t it “implementation” instead of “compile”? Im a newbie too, so I’m not sure but try to change your compile word to implementation.
r

rikusen0335

11/25/2019, 1:28 PM
@Douglas KN I don't need any time library for now. Just I wanted to do is connect to DB.
@Igor Dzichkovskii Okay lemme show that
implementation - Implementation only dependencies for compilation 'main' (target  (jvm)). (n)
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.60 (n)

implementationDependenciesMetadata
+--- org.jetbrains.exposed:exposed-core:0.18.1
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.60
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.60
|    |    \--- org.jetbrains:annotations:13.0
|    +--- org.jetbrains.kotlin:kotlin-reflect:1.3.50
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.60 (*)
|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M1
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.31 -> 1.3.60 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.31 -> 1.3.60
|    \--- org.slf4j:slf4j-api:1.7.25
+--- org.jetbrains.exposed:exposed-dao:0.18.1
|    \--- org.jetbrains.exposed:exposed-core:0.18.1 (*)
+--- org.jetbrains.exposed:exposed-jdbc:0.18.1
|    \--- org.jetbrains.exposed:exposed-core:0.18.1 (*)
+--- org.xerial:sqlite-jdbc:3.21.0.1
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.60 (*)
Maybe this one is that?
i

Igor Dzichkovskii

11/25/2019, 1:35 PM
@rikusen0335 How many Gradle files do you have? In Android there are 2, And it seems like you are trying to do implementation in the wrong Gradle file
r

rikusen0335

11/25/2019, 1:38 PM
if it means only
build.gradle
, I have only 1
Ahh also, I'm developing a minecraft spigot plugin (probably you don't know)
i

Igor Dzichkovskii

11/25/2019, 1:40 PM
In Android it’s like this
r

rikusen0335

11/25/2019, 1:40 PM
Mine is this
i

Igor Dzichkovskii

11/25/2019, 1:57 PM
@rikusen0335 ok, and if you comment the problematic part, is Gradle building without errors? How many libraries do you use?
r

rikusen0335

11/25/2019, 2:00 PM
Yes, gradle builds with no errors.
I don't completely know, but I can show you
build.gradle
:
apply plugin: 'java'
apply plugin: 'kotlin'

group = pluginGroup
version = pluginVersion

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    mavenCentral()
    jcenter()
    maven {
        name = 'papermc-repo'
        url = '<https://papermc.io/repo/repository/maven-public/>'
    }
    maven {
        name = 'sonatype'
        url = '<https://oss.sonatype.org/content/groups/public/>'
    }
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    compile 'org.jetbrains.exposed:exposed-core:0.18.1'
    compile 'org.jetbrains.exposed:exposed-dao:0.18.1'
    compile 'org.jetbrains.exposed:exposed-jdbc:0.18.1'
    compile 'org.xerial:sqlite-jdbc:3.21.0.1'
}

import org.apache.tools.ant.filters.ReplaceTokens

processResources {
    from(sourceSets.main.resources.srcDirs) {
        filter ReplaceTokens, tokens: [version: version]
    }
}
buildscript {
    ext {
        kotlin_version = '1.3.60'
        junit_version = '4.12'
        spigot_version = '1.14.1-R0.1-SNAPSHOT'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
Sorry for too long
i

Igor Dzichkovskii

11/25/2019, 2:09 PM
You put ‘exposed’ 3 times. I’m sure it leads to errors. I can advice you delete the redundant lines and let’s see what will happen
r

rikusen0335

11/25/2019, 2:10 PM
they are not same, core, dao, and jdbc.
maybe I'm talking about wrong?
i

Igor Dzichkovskii

11/25/2019, 2:12 PM
yeah, for real, I didn't notice they aren't the same, haha
@rikusen0335 Stackoverflow says you have to add
Kotlin-reflect
as a dependency. You can try to do it this way: https://stackoverflow.com/questions/48742377/kotlin-gradle-make-sure-you-have-kotlin-reflect-jar-in-the-classpath
r

rikusen0335

11/25/2019, 2:35 PM
but I don't have Module:app, is this affective?
i

Igor Dzichkovskii

11/25/2019, 2:36 PM
I saw in Stackoverflow that somebody put reflect only in build. I’m not sure about it, give it a try
r

rikusen0335

11/25/2019, 2:46 PM
adding like this isn't affect:
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    compile 'org.jetbrains.exposed:exposed-core:0.18.1'
    compile 'org.jetbrains.exposed:exposed-dao:0.18.1'
    compile 'org.jetbrains.exposed:exposed-jdbc:0.18.1'
    compile 'org.xerial:sqlite-jdbc:3.21.0.1'
}
i

Igor Dzichkovskii

11/25/2019, 3:21 PM
I think you should make 2 files of Gradle, bud 😞
r

rikusen0335

11/25/2019, 3:44 PM
😢
I figured it out! The cause is, the plugin Jar file doesn't include exposed libs.
Thank you al so much!!
i

Igor Dzichkovskii

11/25/2019, 5:12 PM
@rikusen0335 yeah, sorry for useless advices 😅
r

rikusen0335

11/25/2019, 5:17 PM
No problem! Thanks anyway