Why rebuild of Kotlin application removes target class files in Eclipse?

107 Views Asked by At

I'm trying to setup an app written in Kotlin, built on Maven and using Spring Boot in Eclipse.

I manage to run the application only if I do Maven build of the project which generates class files in target/classes dir. If I do clean the project then Eclipse rebuilds it automatically and removes all class files from target/classes dir.

I think that re-build of the project should re-compile class files in target/classes directory, not just to remove them. Otherwise it means that I need to re-build project as Maven on each code change which I seems to be a wrong way to go.

Please point me the correct way to setup a Kotlin - Maven - Spring Boot project in Eclipse.

My setup is:

  • Eclipse is 4.26.0.
  • Maven EMBEDDED 3.8.6.
  • Kotlin Plugin for Eclipse 0.8.24 (it causes intallation of Enhanced Kotlin for Eclipse plugin).
  • Spring Tools 4 - 4.17.2.RELEASE.
  • OpenJDK 11.0.2.

What I did:

  1. Installed all the above (Eclipse, plugins, JDK and etc).
  2. Imported the project as a Maven project in Eclipse: github link.

Import dialog

  1. Right click on DemoApplication.kt -> Run As -> 1 Kotlin Application. I got an error:
Error: Could not find or load main class com.example.demo.DemoApplicationKt
Caused by: java.lang.ClassNotFoundException: com.example.demo.DemoApplicationKt
  1. Right click on pom.xml -> Run As -> 2 Maven build...
  2. Goals: clean install -> Run.
  3. After that I see in {project dir}\target\classes\com\example\demo class files were generated.
  4. If then I do right click on DemoApplication.kt -> Run As -> 1 Kotlin Application it runs OK.
  5. If I click on Project -> Clean... (with Build Automatically ON) - all files from {project dir}\target\classes\com\example\demo got removed and I again start at point 3.

I tried couple configuration options, but they didn't help:

  1. Making Window -> Preferences -> Java -> Compiler -> Building -> Output folder -> Scrub output folders when cleaning projects OFF doesn't help - class files still got removed.
  2. In Package Explorer -> Kotlin Runtime Library there is a virtual directory kotlin_bin which has all class files. I tried to setup it as Dependencies:

Run Configuration dependencies setup

But it fails to run then with the below error:

Error when run it

0

There are 0 best solutions below