I am using:
Kotlin 1.3.3
Ktor plugin 1.2.0
IntelliJ IDEA 2019.1.3 (Ultimate Edition) Build #IU-191.7479.7, built
on May 21, 2019
openjdk version "11.0.2" 2019-01-15 - OpenJDK Runtime Environment
18.9 (build 11.0.2+9)
macOS Mojave 10.14.5
Also tried with 'jdk1.8.0_202.jdk/'
I follow the QuickStart from https://ktor.io/quickstart/index.html
When I run the generated code from inside IntelliJ I get:
/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA 2019.1 EAP.app/Contents/lib/idea_rt.jar=50192:/Applications/IntelliJ IDEA 2019.1 EAP.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/classes:/Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/resources:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-server-netty/1.2.0/c30ea7f287343d3007a0794dbfeb3f69aad76ca8/ktor-server-netty-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-html-builder/1.2.0/53ef376dc21a1f404a5154096708fc104092ec77/ktor-html-builder-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-server-host-common/1.2.0/a4335b06f785b39d976e70a00a988bd077beacd1/ktor-server-host-common-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-server-core/1.2.0/4ba64df7deeb3b3cc81b66f005962edfaf63e554/ktor-server-core-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains/kotlin-css-jvm/1.0.0-pre.31-kotlin-1.2.41/718c1d40ec10699ee0ab086e2e9d4d1ebe95646d/kotlin-css-jvm-1.0.0-pre.31-kotlin-1.2.41.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-jetty/1.2.0/3dd4fd4541dd7c85564c65162117a2dd60933f0b/ktor-client-jetty-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-core-jvm/1.2.0/f88e71cffbb49bdba1f1e93131cdee2e2bae0eaa/ktor-client-core-jvm-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-http-cio-jvm/1.2.0/d37a4df9617f49378780554421a3744ab5ceb1d9/ktor-http-cio-jvm-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-http-jvm/1.2.0/aab3e7e34ba1c1947fe362f899d308d97622cfb8/ktor-http-jvm-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-network/1.2.0/bbaefc8c4d66d3707b0a247a341a2f3ea7bd0c5/ktor-network-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-utils-jvm/1.2.0/9d79aff946644c0f489e75f315fcb396f5b4581e/ktor-utils-jvm-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.31/21edc5a6b2e39bc4dc2860346fd778e27503d6cb/kotlin-stdlib-jdk8-1.3.31.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.1/706a8b8206ead3683ec639dd270d11fd948fbb0e/logback-classic-1.2.1.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-core/1.2.0/5788736ce2795078281e5eeb4523e0c81cf8d06/ktor-client-core-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.31/e652770b6416c6d85934086899ffed3eccd35813/kotlin-stdlib-jdk7-1.3.31.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.3.31/5a426a5ada97967ca60fba495eeaa66cfa7c9e2f/kotlin-reflect-1.3.31.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-io-jvm/0.1.8/591b0489ce565c32d4874610ef64c948e6a5c627/kotlinx-coroutines-io-jvm-0.1.8.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-io-jvm/0.1.8/595d4772d0600272bac6a2dcec2646b037285863/kotlinx-io-jvm-0.1.8.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-html-jvm/0.6.12/95dfe9d85947c8dd57c16dced385a37280166e56/kotlinx-html-jvm-0.6.12.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-jdk8/1.2.1/4d891cee198626c08ac30028afdd743558507ad9/kotlinx-coroutines-jdk8-1.2.1.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.2.1/3839faf625f4197acaeceeb6da000f011a2acb49/kotlinx-coroutines-core-1.2.1.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.31/11289d20fd95ae219333f3456072be9f081c30cc/kotlin-stdlib-1.3.31.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-http-cio/1.2.0/9dc1ab0d309da3a03b4e4435b9dc52afbc78c580/ktor-http-cio-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-http/1.2.0/c160a65dea5200650efd8db738fa157d8e7c3f8/ktor-http-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-utils/1.2.0/67edd57c63978974769e6ab6792713d9253c1db9/ktor-utils-1.2.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu/0.12.6/2840b58706d9ef8df7c8aee2e8b6e1444d09df60/atomicfu-0.12.6.jar:/Users/NOTiFY/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/com.typesafe/config/1.3.1/2cf7a6cc79732e3bdf1647d7404279900ca63eb0/config-1.3.1.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec-http2/4.1.24.Final/c0c0d9d20402e4493083447052b59d5680e88b2e/netty-codec-http2-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty/jetty-alpn-openjdk8-client/9.4.15.v20190215/d46fbf9d9c37f75e621a30bf8a192fe2ade30963/jetty-alpn-openjdk8-client-9.4.15.v20190215.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty.alpn/alpn-api/1.1.3.v20160715/a1bf3a937f91b4c953acd13e8c9552347adc2198/alpn-api-1.1.3.v20160715.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-core/1.2.1/378913dfc3c6c71e7e2a2853eff2c3e8ac27599/logback-core-1.2.1.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains/kotlin-css/1.0.0-pre.31-kotlin-1.2.41/c40316f81304348a9983ce15a53c81130b16b36a/kotlin-css-1.0.0-pre.31-kotlin-1.2.41.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-io/0.1.8/ab4c5ab04fe13e78ab0d55d71909b22b6f52f658/kotlinx-coroutines-io-0.1.8.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-common/1.2.1/5806e3dd5e8dff59fec96747795353f3ba2bfd60/kotlinx-coroutines-core-common-1.2.1.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-io/0.1.8/59bcca58d0dae17790c96a775664267ff8492356/kotlinx-io-0.1.8.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.31/20c34a04ea25cb1ef0139598bd67c764562cb170/kotlin-stdlib-common-1.3.31.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty.http2/http2-client/9.4.15.v20190215/dea5744484dbb7e192b6eb061e46d3e53a7edd95/http2-client-9.4.15.v20190215.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty/jetty-alpn-java-client/9.4.15.v20190215/9e513ee27c5ea1fa4d97186e46f613b44e3a7795/jetty-alpn-java-client-9.4.15.v20190215.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu-common/0.12.3/b09ed1e1b1a0996e0a3b6c454797d44788a21747/atomicfu-common-0.12.3.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec-http/4.1.24.Final/8f20009953b2c7c3d860cef928007bc01aa58ac/netty-codec-http-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-handler/4.1.24.Final/bad56e7da211c5ebe031ae155cb648b1065c7bb6/netty-handler-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty.http2/http2-common/9.4.15.v20190215/8983928afb3064fe41b449cabcb827c1024dfba/http2-common-9.4.15.v20190215.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty/jetty-alpn-client/9.4.15.v20190215/1b215197407fdf8582711e32b187ce458c6097d9/jetty-alpn-client-9.4.15.v20190215.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec/4.1.24.Final/290857e5103956bbda11836e33245f2439226b77/netty-codec-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-transport/4.1.24.Final/d37292c94d3a4cba48d9b6cfb6e8e55282035d0d/netty-transport-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-buffer/4.1.24.Final/e354bed2e60b568307138e403f55ba241c1c16d2/netty-buffer-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty.http2/http2-hpack/9.4.15.v20190215/1a2b990e51ea38fb742f7cdec24064c32596edb8/http2-hpack-9.4.15.v20190215.jar:/Users/NOTiFY/.m2/repository/org/eclipse/jetty/jetty-http/9.4.15.v20190215/jetty-http-9.4.15.v20190215.jar:/Users/NOTiFY/.m2/repository/org/eclipse/jetty/jetty-io/9.4.15.v20190215/jetty-io-9.4.15.v20190215.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-resolver/4.1.24.Final/dbc1e5b50d31aed883ea3beeb6489e1977d0687f/netty-resolver-4.1.24.Final.jar:/Users/NOTiFY/.gradle/caches/modules-2/files-2.1/io.netty/netty-common/4.1.24.Final/7eeecd7906543214c3c1c984d275d3c6de10b99d/netty-common-4.1.24.Final.jar:/Users/NOTiFY/.m2/repository/org/eclipse/jetty/jetty-util/9.4.15.v20190215/jetty-util-9.4.15.v20190215.jar com.example.ApplicationKt
2019-05-22 08:08:07.394 [main] TRACE Application - {
# application.conf # file:/Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/resources/application.conf: 6
"application" : {
# application.conf # file:/Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/resources/application.conf: 7
"modules" : [
# application.conf # file:/Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/resources/application.conf: 7
"com.example.ApplicationKt.module"
]
},
# application.conf # file:/Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/resources/application.conf: 2
"deployment" : {
# application.conf # file:/Users/NOTiFY/IdeaProjects/HelloKtorWorld/out/production/resources/application.conf: 3
"port" : 8080
},
# Content hidden
"security" : "***"
}
2019-05-22 08:08:07.885 [main] INFO Application - No ktor.deployment.watch patterns specified, automatic reload is not active
Exception in thread "main" java.lang.ClassNotFoundException: Module function cannot be found for the fully qualified name 'com.example.ApplicationKt.module'
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:367)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:287)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:320)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:286)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartup(ApplicationEngineEnvironmentReloading.kt:302)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:284)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:137)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:257)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:116)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:22)
at io.ktor.server.engine.ApplicationEngine$DefaultImpls.start$default(ApplicationEngine.kt:56)
at io.ktor.server.netty.EngineMain.main(EngineMain.kt:21)
at com.example.ApplicationKt.main(Application.kt:14)
Process finished with exit code 1
Any suggestions, besides look at your stack trace it's a:
java.lang.ClassNotFoundException: Module function cannot be found for the fully qualified name 'com.example.ApplicationKt.module' ?
I ran into same issue. Above mentioned suggestion of changing flag value or deleting file, didn't worked for me.
Root cause of problem, observed in application.conf
Before
modules = [ ApplicationKt.module ]
After
modules = [ com.exp.ApplicationKt.module ]
The full path of Applicationkt.module was changed while relocating files in process of structuring classes by movement[in my case].
The problem is with argument testing: Boolean = false in function Application.module. It looks like that io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction doesn't play well if module has argument(s). Or arguments have to be declared somehow in application.conf file, but this doesn't make sense since it already has default false value. Or we are not building the project correctly.
Just remove the argument from the function, the annotations and delete the ApplicationTest.kt from test folder and you'll good to go.
I had the same problem. It because Kotlin compile Application.kt to ApplicationKt.class (the postfix was added). That's why I need to add Kt postfix to my conf.
modules = [ me.dehasi.httpapi.ApplicationKt.module ]
But the filename is just Application, without Kt.
I came here due to having the exact same error and I'm just trying to learn more about this.
If I remove the parameter to the module, so it looks like this:
#Suppress("unused") // Referenced in application.conf
fun Application.module() {
val client = HttpClient(Apache) {
}
Then it start without any complaints.
Why it works, no idea yet!
Edit:
I used the plugin to setup the project and I'm on java 1.8 (though I don't think it matters here)
Edit 2:
This was how the code was generated for me:
#Suppress("unused") // Referenced in application.conf
#kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
val client = HttpClient(Apache) {
}
there is another solution besides removing the default argument:
add package name on the top of Application.kt, it works for me.
my ktor version is 1.2.2
In my case, I updated my project package but forgot to do the same in application.conf file which returned this error.
Please double check this too.
fun Application.module() should not have parameters
And the definition of the module has to have as a prefix your package and path from source root.
application { modules = [ com.package.app.ApplicationKt.module ] }
Related
I'm a beginner with gradle and would like to use koin in my Kotlin project.
However, I get the following error
Execution failed for task ':compileTestKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':compileTestKotlin'
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not resolve org.jetbrains.kotlin:kotlin-test-junit5:1.6.20.
Required by:
project : > org.jetbrains.kotlin:kotlin-test:1.6.20
> Module 'org.jetbrains.kotlin:kotlin-test-junit5' has been rejected:
Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.6.20' also provided by [org.jetbrains.kotlin:kotlin-test-junit:1.6.10(junitApi)]
> Could not resolve org.jetbrains.kotlin:kotlin-test-junit:1.6.10.
Required by:
project : > io.insert-koin:koin-test:3.2.0-beta-1 > io.insert-koin:koin-test-jvm:3.2.0-beta-1
> Module 'org.jetbrains.kotlin:kotlin-test-junit' has been rejected:
Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.6.10' also provided by [org.jetbrains.kotlin:kotlin-test-junit5:1.6.20(junit5Api)]```
This is my gradle.build.kts file
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val koinVersion = "3.2.0-beta-1"
plugins {
kotlin("jvm") version "1.6.20"
kotlin("plugin.serialization") version "1.6.10"
application
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("io.insert-koin:koin-core:$koinVersion")
testImplementation("io.insert-koin:koin-test:$koinVersion")
testImplementation("io.insert-koin:koin-test-junit5:$koinVersion")
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClass.set("MainKt")
}
It looks like there are 3 problems
As I mentioned in the comment, the Kotlin JVM and Serialization plugins have mismatched versions. These should always be the same!
plugins {
kotlin("jvm") version "1.6.21"
kotlin("plugin.serialization") version "1.6.21"
application
}
However, as you discovered, it still doesn't work. There's a larger error message, with three errors.
Could not resolve io.insert-koin:koin-test-junit5:3.2.0-beta-1
Could not resolve org.jetbrains.kotlin:kotlin-test-junit5:1.6.21
Could not resolve org.jetbrains.kotlin:kotlin-test-junit:1.6.10
Let's go through them one-by-one
Java 11 library, Java 8 project
Here's the reason that Gradle gives for the first failure:
Could not resolve io.insert-koin:koin-test-junit5:3.2.0-beta-1.
No matching variant of io.insert-koin:koin-test-junit5:3.2.0-beta-1 was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but
Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
The component, koin-test-junit5, is only compatible with Java 11, but your project needs Java 8 (kotlinOptions.jvmTarget = "1.8").
Let's fix this first, using Gradle Toolchain
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "11"
}
kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(11))
}
}
That resolves the Java version mis-match, and leaves two more errors.
conflict on capability - incompatible libraries
Cannot select module with conflict on capability
Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.6.10' also provided by [org.jetbrains.kotlin:kotlin-test-junit:1.6.10(junitApi)]
Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.6.10' also provided by [org.jetbrains.kotlin:kotlin-test-junit5:1.6.10(junit5Api)]
Understanding this one requires quite a bit of knowledge of how Gradle selects versions.
tl;dr: org.jetbrains.kotlin:kotlin-test-junit and org.jetbrains.kotlin:kotlin-test-junit5 are incompatible. You can only use one or the other - not both
I don't really understand what Koin needs to work best. It looks like it has a hard dependency on JUnit5, so you'd have to use these dependencies, and wouldn't be able to use kotlin("test")
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("io.insert-koin:koin-core:$koinVersion")
testImplementation("io.insert-koin:koin-test:$koinVersion")
testImplementation("io.insert-koin:koin-test-junit5:$koinVersion")
testImplementation("com.willowtreeapps.assertk:assertk:0.25")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
// incompatible with JUnit 5, which I think is required by Koin?
// testImplementation(kotlin("test"))
}
Explanation
In short, when you use Gradle to build a library, you can declare 'attributes'. They're free-form strings, so they can really be anything. They describe things like "this library needs Java 11" or "this is test coverage data".
Some attributes are important to Gradle resolving a project's dependencies. The error you originally got was caused by one such attribute: 'capability'. It describes the Maven coordinates that the library produces.
In the case of the Maven coordinates, if they clash, then Gradle doesn't know what to do, and throws an error. It's up to the user to fix it. There's a lot of Gradle docs about conflict resolution, but usually the simplest answer is to is remove any conflicting dependencies.
What's interesting about capabilities is that because it's just a string, you can add anything to it. And what the authors of org.jetbrains.kotlin:kotlin-test-junit5 and org.jetbrains.kotlin:kotlin-test-junit have done is given them both the same capability.
org.jetbrains.kotlin:kotlin-test-framework-impl:1.6.10
If you search for this library you'll find it doesn't exist. That's because the capability is completely artificial! The authors have made it up, specifically so Gradle will throw an error, and it's up to the user to fix it.
So that's the fix: choose either kotlin-test-junit or kotlin-test-junit5, because you can't have both.
I think org.jetbrains.kotlin:kotlin-test-junit5 has problem with dependencies.
I also struggled with the same issue, so I tried multiple solutions but it all fails.
And I realized that, when just add dependency for kotlin-test-junit5, the kotlin-test-junit is also added to the external libraries.
So here's the working solution for me.
I added this line to gradle first to enable useJunitPlatform()
tasks.withType<Test> {
useJUnitPlatform()
}
after that, i exclude kotlin-test-junit from every references like this,
testImplementation("io.ktor:ktor-server-tests-jvm:$ktorVersion")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVersion") {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-test-junit")
}
// Dependency Injection
val koinVersion: String by project
implementation("io.insert-koin", "koin-ktor", koinVersion)
implementation("io.insert-koin", "koin-logger-slf4j", koinVersion)
testImplementation("io.insert-koin", "koin-test-junit5", koinVersion) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-test-junit")
}
After that, junit5 test was working perfectly.
I have a Kotlin multiplatform project and the newest version of IDEA started to complain about #JvmStatic usages in interfaces:
What's weird is that I added the necessary config to my build.gradle.kts file:
kotlin {
jvm {
withJava()
jvmTarget(JavaVersion.VERSION_1_8)
}
// ...
}
and I also set it up in IDEA here:
and here:
and I also added the compiler parameter as IDEA suggested. What am I doing wrong?
If I build the project from the command line I get a BUILD SUCCESSFUL.
This is a bug with multiplatform projects Gradle IDEA import: https://youtrack.jetbrains.com/issue/KT-43074. In this particular case it is acceptable to suppress the error until the bug is fixed:
#Suppress("JVM_STATIC_IN_INTERFACE_1_6") // remove when KT-43074 is fixed
fun empty() = ...
class Foo(
val name: Identifier,
val trKey: String = "action.${name.toString().replace(':', '.')}"
// ^~~~~~~ this is unresolved
) {
// Members
}
The replace function is able to be resolved in Fabric's source code and it does run, but it doesn't in my Kotlin code.
I've tried setting the project SDK to 1.8, 11, and Kotlin SDK, and none of them seem to solve this issue. In fact, putting the SDK to 11 makes java.lang.String inaccesible.
I think I fixed it by adding KotlinRuntime into libraries through IntelliJ project structure (will get erased by Gradle import), or with gradle dependencies adding Kotlin library.
Instead I found changing JDK version back to 1.8 fixes this issue and is reproducable. The above only worked once for me.
I installed the latest version of Intellij on Linux (2019.2.3 Community Edition) and added the Kotlin plugin.
I followed the Kotlin website's Getting Started with IntelliJ IDEA and created a hello world app. It worked fine until I added a LinkedHashMap. (BTW, I was running into this in a bigger project, but simplified it to this.)
This is all the code I added:
import kotlin.collections.LinkedHashMap
fun main(args:Array<String>) {
println("Hello world")
val map: LinkedHashMap<Int, String> = linkedMapOf(1 to "x", 2 to "y", -1 to "zz")
println(map)
}
I get this error on the map line:
Cannot access class 'java.util.LinkedHashMap'. Check your module classpath for missing or conflicting dependencies.
You can see I have 1.8 selected in the modules, and I verified java 8 is installed via terminal (java -version). What is the issue for this vanilla/default installation?
Ok, so I figured it out. For some reason, if I change the module to 11 (java 11) from 1.8 it just works.
Kind of weird that standard collections don't work out of the box, but... eh, I guess this works.
I am trying to use apache-ldap-api with grails 2.2 . The latest version of the api on their website is 1.0.0-M15 , but maven repo has upto 1.0.0-M13 . So I decided to use M13 first by adding a dependency to BuildConfig.groovy:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
runtime(
[group: 'org.apache.directory.shared', name: 'apache-ldap-api', version: '1.0.0-M13']
)
// runtime 'mysql:mysql-connector-java:5.1.20'
}
Grails downloaded the dependency alright, but when I try to use the API in the code such as:
import org.apache.directory.groovyldap.LDAP
LDAP.newInstance(...)
I get a compile error :
LdapController.groovy: 2: unable to resolve class org.apache.directory.groovyldap.LDAP
# line 2, column 1.
import org.apache.directory.groovyldap.LDAP
^
1 error
The compiler lets me import 'org.apache.directory.groovyldap.*' but then again, the call to 'LDAP.newInstance()' throws an exception.
I also tried manually dropping the 1.0.0-M15 version in my /lib folder and running 'grails compile --refresh-dependencies' without any luck. Any ideas if I am doing something wrong here?
Thanks!
1 run this grails compile --refresh-dependencies
2 change LDAP.newInstance(...) into new LDAP
This is how it works for me