[SOLVED] Kotlin with M2E


Hi, just new to Kotlin but I wanted to see if I can integrate it with my test project. I tried to follow the instructions in Using Maven and created a simple JUnit file like based on the example. I am using 1.1.2-3

I have two issues:

  1. When I ran it on Maven I got the following error

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.1.2-3:test-compile (test-compile) on project jee-domain: Compilation failure
[ERROR] D:\p\jee\jee-domain\src\test\kotlin\net\trajano\jee\domain\kotlin\test\KotlinSanityTest.kt:[7,3] Cannot access class ‘kotlin.reflect.KClass’. Check your module classpath for missing or conflicting dependencies

  1. On Eclipse it does not automatically register src/main/kotlin and src/test/kotlin as a source folder.

The app I have is

The changes are small to add the kotlin support as specified by Using Maven



AFAIK, dependencyManagement block is used to specify versions of your dependencies, but not to add them automatically to the classpath. So you need to specify kotlin-stdlib also (or solely) in project/dependencies block.

More about difference between dependencyManagement and dependencies: http://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven


doh! you’re right missed that one. derp.

And it worked at least on the command line. However issue 2 with M2E is still there. Anyway I can have it automatically add the paths into M2E.

Actually I was wondering if I can just plop the kotlin code into src/main/java


Nope that didn’t work. when I try to execute the JUnit for Kotlin in src/test/java I don’t see it when I try to execute on the src/test/java It runs when I do the specific test though. The good part is it works on the maven build line, just not on the Eclipse.


It’s ok to place kotlin files in java source directory.
For running tests written in kotlin you may need this additional configuration of surefire plugin to find not only tests with .java extension:



There’s no need for that change in maven configuration. It works already with no configuration from what I can tell in the log https://travis-ci.org/trajano/jee/builds/231232907#L627

You can see the result as well here https://site.trajano.net/jee/jee-domain/surefire-report.html

I guess the only issue left is doing a test executions in Eclipse from the package or directory level. Hopefully a new version of the Kotlin Eclipse plugin (I think) can handle that.

Something around

But those will define a new launch, I don’t really see an extension point to JUnit itself, To change how it calculates the suites. EclEmma may have some code for that.


One other thing that is missing


The maven-javadoc-plugin does not process Kotlin code (well I wasn’t expecting it to considering the newness, but I think it should have it there).