Copy-pasta from <#C0922A726|general> Hello, I'm ne...
# getting-started
r
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
Hi, how is your exposed dependency set up in Gradle?
r
Thanks for replying. in
build.gradle
,
Copy code
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
I'm sorry I tried that. like this. isn't worked:
Copy code
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
for your db path does it work if you use a file?
"jdbc:sqlite:test.sqlite"
m
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
@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:
Copy code
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
@rikusen0335 do you need to include one of the time modules? exposed-jodatime or exposed-java-time
i
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
@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
Copy code
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
@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
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
In Android it’s like this
r
Mine is this
i
@rikusen0335 ok, and if you comment the problematic part, is Gradle building without errors? How many libraries do you use?
r
Yes, gradle builds with no errors.
I don't completely know, but I can show you
build.gradle
:
Copy code
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
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
they are not same, core, dao, and jdbc.
maybe I'm talking about wrong?
i
yeah, for real, I didn't notice they aren't the same, haha
@rikusen0335 Stackoverflow says you have to add
Copy code
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
but I don't have Module:app, is this affective?
i
I saw in Stackoverflow that somebody put reflect only in build. I’m not sure about it, give it a try
r
adding like this isn't affect:
Copy code
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
I think you should make 2 files of Gradle, bud 😞
r
😢
I figured it out! The cause is, the plugin Jar file doesn't include exposed libs.
Thank you al so much!!
i
@rikusen0335 yeah, sorry for useless advices 😅
r
No problem! Thanks anyway