1

I created a mixed project Java+Kotlin in eclipse oxygen. I added the kotlin plugin to eclipse and added kotlin nature to the project. No problem compiling or building with maven.

When I executed the project I got an exception because the kotlin runtime jar is not there. No problem again, I added the jar manually in the run configuration like so:

enter image description here

But this is a hack.

Can anybody tell me the most elegant way to tell eclipse to add the same runtime used by the eclipse kotlin plugin when I execute the program so that said runtime jar will stay in sync if I ever update the plugin.

If it helps, this is what the library looks like in the project's build path:

enter image description here

It seems simple enough but I can't figure the right way to do it...

3
  • 1
    Shouldn't it be in your pom.xml? Commented Aug 29, 2017 at 23:38
  • @nitind do you mean the kotlin runtime as a dependency? Commented Aug 30, 2017 at 0:10
  • I just tried adding it as a dependency and it worked indeed. It threw me off that eclipse doesn't need it for compilation as the library is added when adding the kotlin nature to the project Commented Aug 30, 2017 at 0:18

1 Answer 1

1

As I mentioned in the comment above, the fact that one doesn't need to add anything in Maven to have eclipse compile the Kotlin classes but needs the maven dependency to run it, confused me.

In order to run a Maven project with a Kotlin nature, containing Java and Kotlin code in Eclipse + Kotlin plugin, it is necessary to add the runtime as a dependency in the pom.xml.

    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-runtime</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

Incidentally it is also advisable to add the standard library since, in all likelyhood, classes from it will be needed by the code.

The second part is finding out the right version of Kotlin to use, which has to be the same used by the plugin.

For that, we can check the plugin version

enter image description here

The version of the compiler is already there (1.1.1 in this case), but we can also ensure this by going to the public Kotlin plugin source code repository.

In github select the correct branch. Probably "master" if the plugin is up to date. And check the Kotlin version in the pom.xml.

If that version is not in the maven central it will be necessary to add the pertinent repository both under the repositories and pluginRepositories sections in the pom.xml.

Don't remove the Kotlin library from the libraries tab in the classpath section of the project properties dialog (it's what appears in the image in my question above)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.