Adding external Libraries
-
Hi there,
I'm new to Kotlin and very new to KorGE. I tried to read JSON-Data in a KorGE application, but can't get any library to work.
Right now I tried to use the kotlinx-serilization and added this classpath to the dependency-section of the standard KorGE build.gradle.kts file:
```
classpath( "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0")Gradle downloads the dependency, but the libs don't appear in the external Libraries and I can't reference anthing in the code. I'm not set on this specific lib, anything that can parse Json to classes would be welcome. I couldn't find any examples where KorGE-Applications use other libraries, so I'm kind of stuck. Any help would be great. Thanks a lot, Rainer
-
I also did not find the answer in the documentation. The solution helped me:
(build.gradle.kts)korge {
id = "com.example.example" version = "0.0.1" name = "testapp" dependencyMulti("casper.types:typesKt:1.0.1")
}
There is probably a simpler and more obvious solution. but the gradle is hard for me -
Thanks for this tip, but I still struggle with the gradle part.
When I add the lib like this:korge { id = "test" dependencyMulti("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0") }
I still can't get it to work. I can't reference it in the code, an when I use the run-korge task, I get this error
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':genResources'. > Could not resolve all files for configuration ':detachedConfiguration1'. > Could not find org.jetbrains.kotlinx:kotlinx-serialization-runtime-jvm:0.20.0. Searched in the following locations: - file:/home/rainer/.m2/repository/org/jetbrains/kotlinx/kotlinx-serialization-runtime-jvm/0.20.0/kotlinx-serialization-runtime-jvm-0.20.0.pom - https://dl.bintray.com/korlibs/korlibs/org/jetbrains/kotlinx/kotlinx-serialization-runtime-jvm/0.20.0/kotlinx-serialization-runtime-jvm-0.20.0.pom - https://jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-serialization-runtime-jvm/0.20.0/kotlinx-serialization-runtime-jvm-0.20.0.pom - https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-runtime-jvm/0.20.0/kotlinx-serialization-runtime-jvm-0.20.0.pom Required by: project :
I suspect the multiplatform, or the korge plugin rename the lib from kotlinx-serialization-runtime:0.20.0 to kotlinx-serialization-runtime-jvm-0.20.0
but I have no workaround for this.So any help would be great.
Thanks,
Rainer -
-
I think we need to wait for the author’s response.
All proposed solutions do not work in particular when trying to build an android. -
Thanks for the support, but I haven't been successful yet.
I started a new projet in Intellij and used the korge defaults.
Then I added this to the build.grade.kts (Nicos tipp):repositories { mavenCentral() mavenLocal() } dependencies { add("commonMainApi", dependencyNotation = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0") }
At this stage I can build and run (korge-runjvm) the project. Also the kotlinx.serilization,runtime lib is visible in the external libraries.
But as soon as I want to use the library in the main.kt, like adding
val j = Json(JsonConfiguration.Default)
IntelliJ cannot find the classes.
I also cannot import the stuff by hand:import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration
results in "unresoved reference: serilization"
I'm sorry, but I really struggle with the gradle-tooling here. I find it very hard to find references, let alone understand the connections of gradle, gradle.kotlin, gradle-kroge-plugin and the use of the different scopes and notations in all of them.
So if there are any more ideas, I'm still interrested in trying
Thanks a lot,
Rainer -
Have a look to this build.gradle:
https://github.com/mmo-poc/mmo-poc/blob/master/build.gradle
For kotlinx serializaiton, you have to apply the plugin and include a few artifacts
-
Thanks for this hint.
I added the kotlinx serilization and appled the plugin, resulting in this build.gradle.kts:
import com.soywiz.korge.gradle.* buildscript { val korgeVersion: String by project val kotlinVersion: String by project repositories { mavenLocal() maven { url = uri("https://dl.bintray.com/korlibs/korlibs") } maven { url = uri("https://plugins.gradle.org/m2/") } maven { url = uri( "https://dl.bintray.com/kotlin/kotlin-dev/")} mavenCentral() } dependencies { classpath("com.soywiz.korlibs.korge.plugins:korge-gradle-plugin:1.13.2.3") classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") } } apply<KorgeGradlePlugin>() apply(plugin = "kotlinx-serialization") korge { id = "com.example.example" } repositories { mavenCentral() mavenLocal() } dependencies { add("commonMainApi", dependencyNotation = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0") }
But this wasn't enough, as I still cannot use the lib in the main.kt
I think I'm missing this part, using implementation, from the given example:
subprojects { apply plugin: "kotlin-multiplatform" apply plugin: "kotlinx-serialization" kotlin { jvm { ... } } js { ... } sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationRuntimeVersion" ...
But I faild to include something equivalent in my build.gradle.kts.
I also tried to use the build,gradle from the example and adapt it, but gave up after several attempts...
Maybe I have to do some serious research on gradle, gradle-kotlin-dsl and the gradle korge plugin, before I try this again...Thanks for all the help!
Rainer -
I have the same issue. I was able to get my package to download via
repositories { // https://stackoverflow.com/questions/59413364/upgrading-from-gradle-5-1-1-to-6-0-1-breaks-kotlin-multiplatform-build jcenter { metadataSources { gradleMetadata() mavenPom() } } jcenter() } dependencies { add("commonMainApi", "com.github.glwithu06.semver:semver:1.0.1") }
but I cannot resolve it in my code, it's like it's not on the classpath
I also tried usingplugins { java } dependencies { implementation("com.github.glwithu06.semver:semver:1.0.1") }
but does not even add it to my external dependencies (although it's downloaded and it's in my modules-2 gradle cache folder along with sources jar, main jar and pom.xml
any ideas?