Unresolved reference for gradle dependency - kotlin

All the classes of the library are shown in the libs folder but when I try to use any reference to it, it just says it is an unresolved reference.
Unresolved reference error
build.gradle.kts:
plugins {
kotlin("jvm") version "1.8.0"
kotlin("plugin.serialization") version "1.8.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.papermc.paperweight.userdev") version "1.3.6"
}
group = "me.supehsloht"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://repo.rapture.pw/repository/maven-snapshots/")
}
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.8.0")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
compileOnly("com.charleskorn.kaml:kaml:0.49.0")
paperDevBundle("1.19.3-R0.1-SNAPSHOT")
compileOnly(files("libs/Core.jar"))
compileOnly(files("libs/AdvancedSlimeWorldManagerAPI.jar"))
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
reobfJar {
outputJar.set(layout.buildDirectory.file("libs/${project.name.capitalize()}.jar"))
}
}
I already had this problem, then it was fixed by not shading the kotlin stdlib into the jar but that didn't work this time.

Related

IntelliJ IDEA could not found the kotlin test dependency Library, but I have kotlin("test") for gradle.build.ks

I created a kotlin project through the project creation wizard of Intellij IDEA.
I just created a test file to verify the demo of kotlin official website.
A demo for Intellij IDEA, but it not find to 'kotlin.test.Test'.
internal class ATest {
#kotlin.test.Test
fun sum() {
}
}
IDEA UI IMAGE
This is my 'gradle.build.ks' file.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

Kotlin NoSuchMethodError after installing a library that enables a plugin

I want to experience a library called arrow analysis
My build.gradle.kts file looks as follows:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("io.arrow-kt:arrow-core:1.1.2")
}
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
after an attempt to build the project, I get the following error:
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.psi.KtExpression org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt.getReceiverExpression(org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)'
at arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.KotlinResolvedCall.getReceiverExpression(KotlinResolvedCall.kt:37)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.allArgumentExpressions(ResolvedCallUtils.kt:75)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.arg(ResolvedCallUtils.kt:119)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.controlFlowAnyFunction(Expressions.kt:438)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.checkCallExpression(Expressions.kt:397)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.fallThrough(Expressions.kt:260)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.access$fallThrough(Expressions.kt:1)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:244)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:157)
at arrow.meta.continuations.ContSeq$flatMap$1.invokeSuspend(ContSeq.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
I checked the source code, and everything seems to be in place. Did I something wrong as per the instructions to install this library which is denoted as follows:
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
You need to apply the plugin inside the plugins block and in the same fashion you're applying the Kotlin JVM plugin.
They mention to use it like this on their official docs
plugins {
kotlin("multiplatform") version "1.6.21"
// other plugins
id("io.arrow-kt.analysis.kotlin") version "2.0.2"
}
buildscript {
repositories {
mavenCentral()
}
}

How to package a kotlin project with JavaFX in it?

my team got a kotlin project with JavaFX as frontEnd. The problem we have is using jlink to produce a package.
Here is my build.gradle for the project.
Could anyone help me take a look at how to change this?
ps: I have already tried with
command-line javac
jlink from the intellij
create a new Main method and use the shadow plugin for jlink.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
plugins {
id "java"
id "application"
id "org.jetbrains.kotlin.jvm" version "1.6.10"
id "org.openjfx.javafxplugin" version "0.0.12"
id "org.beryx.jlink" version "2.25.0"
// Json
id "org.jetbrains.kotlin.plugin.serialization" version "1.6.10"
}
group "com.yyil"
version "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
ext {
junitVersion = "5.8.1"
}
sourceCompatibility = "16"
targetCompatibility = "16"
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
application {
mainClass = 'com.yyil.noteapp.NewMain'
}
[compileKotlin, compileTestKotlin].forEach {
it.kotlinOptions {
jvmTarget = "16"
}
}
javafx {
version = "17.0.2"
modules = ["javafx.controls", "javafx.fxml", "javafx.web", "javafx.swing", "javafx.graphics", "javafx.base"]
}
dependencies {
implementation("org.controlsfx:controlsfx:11.1.0")
implementation("net.synedra:validatorfx:0.1.13") {
exclude(group: "org.openjfx")
}
implementation("org.kordamp.ikonli:ikonli-javafx:12.2.0")
implementation("eu.hansolo:tilesfx:11.48") {
exclude(group: "org.openjfx")
}
// JSON
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
// testing JavaFX
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
testImplementation("org.testfx:testfx-core:4.0.16-alpha")
testImplementation("org.testfx:testfx-junit5:4.0.16-alpha")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
// database (sqlite)
implementation "org.xerial:sqlite-jdbc:3.30.1"
// svg support
implementation("org.apache.xmlgraphics:batik-transcoder:1.14")
}
test {
useJUnitPlatform()
}
When I try to build it, I got errors like:

Kotlin Multiplattform Project Dependencies

What do I do wrong, I just want to add dependencies to my multiplattform project (at the moment just windows):
I just added some example repository and dependencies.
plugins {
kotlin("multiplatform") version "1.5.0"
kotlin("plugin.serialization") version "1.5.0"
}
kotlin {
allprojects {
repositories {
mavenCentral()
google()
jcenter()
maven { setUrl("https://jitpack.io") }
}
}
sourceSets {
commonMain {
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.9.1")
implementation("io.ktor:ktor-server-netty:1.5.4")
implementation("io.ktor:ktor-server-core:1.5.4")
}
}
}
}
kotlin {
mingwX64("native") {
binaries {
executable()
}
}
}
tasks.withType<Wrapper> {
gradleVersion = "7.0.1"
distributionType = Wrapper.DistributionType.ALL
}
Outcome:
Output
I would guess none of those dependencies are actually available for windows. You'll need windows compatible ktor dependencies (and I'd stick to Kotlin 1.4.32 vs 1.5 because of kotlinx.coroutines, for now).
Ktor config for windows is probably like this, but I've never done this for Windows.
sourceSets {
commonMain {
dependencies {
implementation "io.ktor:ktor-client-core:$ktor_version"
}
}
mingwX64Main {
dependencies {
implementation "io.ktor:ktor-client-curl:$ktor_version"
}
}
}

Linking dependencies with Gradle 6.5 in a Kotlin Multiplatform Multimodule project

I have the following structure and i want to include integration-jvm-1 as a dependency inside module-mp-1 and inside application-jvm-1, i want to include module-mp-1's JVM output as dependency.
See the sample project on Github:
https://github.com/JVAAS/kotlin-multiplatform-multi-module-setup
Here's the overview of what i've done so far:
generic-project
+-- applications
+-- application-jvm-1
+-- integrations
+-- integration-jvm-1
+-- modules
+-- module-mp-1
build.gradle.kts
settings.gradle.kts
my build.gradle.kts is empty, settings.gradle.kts is as follow:
rootProject.name = "generic-project"
include("applications:application-jvm-1")
include("modules:module-mp-1")
include("integrations:integration-jvm-1")
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
}
}
}
applications/application-jvm-1/build.gradle.kts is as follow
(note the api(project(":modules:module-mp-1")) dependency)
plugins {
val kotlinVersion = "1.4-M2"
application
kotlin("multiplatform") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
}
group = "com.generic.applications"
version = "1.0.0"
repositories {
jcenter()
mavenCentral()
maven {
url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
}
maven {
url = uri("https://kotlin.bintray.com/kotlinx")
}
gradlePluginPortal()
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"
}
}
sourceSets {
val serializationVersion = "0.20.0-1.4-M2"
val coroutinesVersion = "1.3.7-1.4-M2"
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
api(project(":modules:module-mp-1"))
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
all {
languageSettings.enableLanguageFeature("InlineClasses")
}
}
}
application {
mainClassName = "Application"
}
integrations/integration-jvm-1/build.gradle.kts is as follow:
plugins {
val kotlinVersion = "1.4-M2"
kotlin("multiplatform") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
}
group = "com.generic.integrations"
version = "1.0.0"
repositories {
jcenter()
mavenCentral()
maven {
url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
}
maven {
url = uri("https://kotlin.bintray.com/kotlinx")
}
gradlePluginPortal()
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"
}
}
sourceSets {
val serializationVersion = "0.20.0-1.4-M2"
val coroutinesVersion = "1.3.7-1.4-M2"
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
// logging
val slf4jVersion = "1.7.25"
val logbackVersion = "1.2.3"
implementation("org.slf4j:slf4j-api:$slf4jVersion")
implementation("org.slf4j:jcl-over-slf4j:$slf4jVersion")
implementation("org.slf4j:jul-to-slf4j:$slf4jVersion")
implementation("org.slf4j:log4j-over-slf4j:$slf4jVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
all {
languageSettings.enableLanguageFeature("InlineClasses")
}
}
}
/modules/module-mp-1/build.gradle.kts is as follow:
(note the dependency api(project(":integrations:integration-jvm-1")))
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4-M2"
}
group = "com.generic.modules"
version = "1.0.0"
repositories {
mavenCentral()
jcenter()
maven {
url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
}
}
dependencies {
testImplementation(kotlin("test-junit5"))
implementation(kotlin("stdlib-jdk8"))
// ktor
val ktorVersion = "1.3.1"
//implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-server-cio:$ktorVersion")
implementation("io.ktor:ktor-html-builder:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.1")
// logging
val slf4jVersion = "1.7.25"
val logbackVersion = "1.2.3"
implementation("org.slf4j:slf4j-api:$slf4jVersion")
implementation("org.slf4j:jcl-over-slf4j:$slf4jVersion")
implementation("org.slf4j:jul-to-slf4j:$slf4jVersion")
implementation("org.slf4j:log4j-over-slf4j:$slf4jVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
api(project(":integrations:integration-jvm-1"))
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
}
When i pull Generic Project into IntelliJ and do a gradle refresh, i'm not getting error, but i'm also unable to get it to compile when i use module dependencies inside application
import com.generic.modules.Module1 <<-- unresolved reference modules
object Application {
#JvmStatic
fun main(args: Array<String>) {
println("TEST")
println(Module1().toString())
}
}
Any ideas?
I've made a sample project on Github with all of the above
https://github.com/JVAAS/kotlin-multiplatform-multi-module-setup
If this directory structure is making it more difficult than it should be, then i'm happy to change that too. Just want dependencies working one way or another.
Building Multiplatform Projects with Gradle is the best resource on this topic. Specifically in Adding Dependencies it says:
a project('...') dependency on another multiplatform project is resolved to an appropriate target automatically. It is enough to specify a single project('...') dependency in a source set's dependencies, and the compilations that include the source set will receive a corresponding platform-specific artifact of that project, given that it has a compatible target.
The article also contains examples on how to configure project dependencies.