Last week I asked if Spek was on a Maven repository so I could easily add it to my project and test it.

Someone who will remain anonymous (who still needs to wash my car) and runs the Spek project told me it wasn’t and that I could be so nice to add it.

I know next to nothing about Maven, except that it exists. So I went on the Google and found… a lot of things that I didn’t know about. But in the end I found this.

And that helped just a little.

Setting up Maven

Apparently everybody knows how to set up Maven but forget to tell how it is done.

So first of all I downloaded Maven 3.0.4 and then unzipped that in the Program files folder (x86). Then I had to add this E:Program Files (x86)apache-maven-3.0.4bin to my Path in the System Variables whiyou can find in Control Panel -> System -> Advanced settings -> Environment variables. I also needed to add the system variable JAVA_HOME and set it to this E:Program Files (x86)Javajdk1.7.0jre or the path to your jre of your JDK.

You can also add the system variable M2_HOME and set it to this E:Program Files (x86)apache-maven-3.0.4 or not. You can choose to add it manually to your module too.

If you get this error

Error running kotlindeom [test]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.

then the above did not work. In Intellij go to File -> Settings -> Maven and copy the Maven directory in the Maven home directory field.

And now Maven works with Intellij 12. Oh joy.


It is now time to make our project.

Make a new project and make it a Maven module.

use the quickstart archetype, or any other archetype since we are not going to use it anyway.

override the maven home directory if you did not set M2_HOME or if you so desire.

Now we can change the pom.xml file to this.

<project xmlns="" xmlns:xsi=""











If everything is well you should not see any red in there.

Does it work?

Now we can start adding our kotlin files in.

Create a package kotlin.kotlindemo in the main and remove the package java. Add a kotlin file to that and use this code.

```java package demo

data class MyClass(val i : Int, val s : String)``` Now add a kotlin.kotlindemo package to the test folder and add a kotlin file.

With this code.

```java package demo.test

import demo.MyClass import kotlin.test.assertEquals import org.junit.Test as test import kotlin.test.assertTrue import kotlin.test.assertFalse

public class TestMyClass { test fun IfPropertyIIsSetCorrectly() { val c1 = MyClass(1,“t”) assertEquals(1,c1.i) }

test fun IfPropertySIsSetCorrectly()
    val c1 = MyClass(1,"t")

test fun If2MyClassesWithTheSamePropertiesAreEqual()
    val c1 = MyClass(1,"t")
    val c2 = MyClass(1,"t")

test fun If2MyClassesWithDifferentPropertiesAreNotEqual()
    val c1 = MyClass(1,"t")
    val c2 = MyClass(2,"t")

test fun IfToStringReturnsTheCorrectString()
    val c1 = MyClass(1, "t")
    assertEquals("MyClass(i=1, s=t)",c1.toString())

}``` You might think this is the same class as in my previous blogpost but it isn’t. My previous class was called testMyClass and by convention Maven only finds Test*, *Test or TestCase* classes. I found that out the hard way. Lucky me.

Anyway, your project should look like this.

And now when we open our Maven project view. we should see this.

you can now doubleclick on test and see the magic happen.

This should be the result.

5 tests run and none faild. Woohoo.


It took me a while to get it to work since I could not find Maven and IntelliJ for dummies and the Maven site is full of XML. But it works and I’m happy. Now on to Spek and getting the package into a repo, be afraid, be very afraid.