Issue with Coroutine Libraries depending on build setuo

已回答

Depending on the build setup, there appears an NoClassDefFoundError error or not. It all points towards a mixup with the proper reference to the coroutine libraries, but I can't figure it out. Any idea, what is wrong?

I have uploaded the two projects with upload reference: 2022_06_19_iJ3YYaMyvrfCjPaqn2d74t.

Project 1: A pure Maven managed project (just a pom.xml file and no iml file).
I don't know anymore how I had come to this setup. But I have not used the project creation assistant for it. May be a copy from some project I downloaded from somewhere.
Anyway, the little test call of the delay function in "suspend main()" works fine.

Project 2: A project created with the IntelliJ project creation assistant.
I chose simple "New project" with Language = Kotlin and Build System = Maven. When adding the little "delay" test function, IntelliJ creates the iml file (in addition to the pom.xml file).
That program fails and throws an error:
   Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/KotlinNothingValueException
      at test.DelayTestKt.main(DelayTest.kt:7) ......

Interesting observation: The help guide published in https://www.jetbrains.com/idea/guide/tutorials/working-with-maven/creating-a-project/ shows a "Maven" object in as first item in the left hand menu bar in the screenshots shown. I don't have that. Why?
I checked the plugins and it says, that Maven support is bundled in already. Is that the reason why I don't see that option.

My workbench version:

IntelliJ IDEA 2022.1.2 (Community Edition)
Build #IC-221.5787.30, built on May 31, 2022
Runtime version: 11.0.15+10-b2043.56 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

 

评论操作 固定链接

You have to change your version of coroutines library from: 

<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-swing</artifactId>
<version>1.6.1-native-mt</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.3.8</version>
</dependency>

to:

<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-swing</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.6.4</version>
</dependency>

 

We changed the Project Wizard recently, so you need to choose `New Project -> Build System: Maven`.

0
评论操作 固定链接

Thanks, Ivan. That fixed the problem with Project 2. But notice that this is the project that I actually created as instructed (`New Project -> Build System: Maven`). 

Why does Project 1 work even though it works with versions '1.6.1-native-mt' and '1.3.8'? 

0
评论操作 固定链接

Try to resync the project fully.

1. Open `Project Structure | Modules | Dependencies`, remove all Maven entries.

2. `Maven | Clean then reimport maven project`

3. Run the `main` function.

0
评论操作 固定链接

I want to demonstrate that Project 1 also fails (since it runs with the wrong libraries). I did step 1.

How exactly do I do step 2? I did not know and ran instead the "Reload all Maven Projects" functions in the Maven tab. Afterward the project still works. The dependencies for the module got restored and still show the versions that are supposed NOT to work.

So, I guess the "Clean/re-import" step is crucial and I do not know how to do that exactly.

0
评论操作 固定链接

Sorry, I was wrong. Looks like the problem in combination of these old versions and `kotlin-stdlib-jdk8`. If you change this dependency to `kotlin-stdlib` everything works fine. Also, everything works with the new versions of `kotlin-stdlib-jdk8` and coroutines' depenendencies.

0

请先登录再写评论。