I'm interested in this question, too.
I start with a Maven project, I add Evgeny Goldin’s plugin
http://evgeny-goldin.com/wiki/Kotlin-maven-plugin
to the existing POM, I create manually src/[main,test]/kotlin, and add a Kotlin file to src/main/kotlin that uses stdlib (say, println()). I’m including my POM as a reference. It seems like we should add the kotlin runtime as at least a Maven “provided” scope dependency. So I did this by doing a manual install-jar operation within maven to install the kotlin runtime to the local repository. Then add the runtime as a dependency – I used version 1.0 for the runtime because it was easy to type
I also have a Java main class defined that instantiates a Kotlin class which contains a function that prints “hello”. This much works for me when I run the app from within the IDE using App#main as an entry point.
I do notice that once in a while, IJ will unmark src/[main,test]/kotlin as source roots. Not sure what is going on there.
Here is my POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.petrovic</groupId>
<artifactId>mailchimp-kotlin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mailchimp-kotlin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.mailjimp</groupId>
<artifactId>mailjimp-core</artifactId>
<version>0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.goldin.plugins</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>0.2.3.8-beta-6</version>
<executions>
<execution>
<id>compile-kotlin-sources</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<src>${project.basedir}/src/main/kotlin</src>
<output>${project.build.outputDirectory}</output>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.goldin.plugins</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.mailjimp</groupId>
<artifactId>mailjimp-core</artifactId>
</dependency>
<dependency>
<!-- manually added the runtime to mvn repo using rt jar from another newly created kt project –>
<groupId>com.jetbrains</groupId>
<artifactId>kotlin-runtime</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>kotlin plugin repo</id>
<url>http://evgeny-goldin.org/artifactory/repo/</url>
</pluginRepository>
</pluginRepositories>
</project>
Here is my main Java class:
package org.petrovic.mailchimp;
import mailjimp.dom.response.list.MailingList;
import mailjimp.service.MailJimpException;
import mailjimp.service.impl.MailJimpJsonService;
import java.util.List;
public class App {
public static void main(String args) throws MailJimpException {
App app = new App();
app.run();
}
private void run() throws MailJimpException {
String userName = “blah”;
String password = “foo”;
String apiKey = “thekey”;
String apiVersion = “1.3”;
boolean ssl = false;
MailJimpJsonService mailJimpJsonService = new MailJimpJsonService(userName, password, apiKey, apiVersion, ssl);
mailJimpJsonService.init();
List<MailingList> lists = mailJimpJsonService.lists();
for (MailingList list : lists) {
System.out.println(list);
}
ChimpUtils c = new ChimpUtils(1);
c.foo();
}
}
And here is the Kotlin class:
package org.petrovic.mailchimp
class ChimpUtils(param : Int) {
val property = param
fun foo() {
println(“hello”)
}
}
I have no idea if I’m using the “package” statement correctly in the Kotlin file. It feels like I may be lugging some Java paradigms into a realm where I may not need them? Maybe not. I need to read the docs. Seems like I should know something about Kotlin modules before going much further.
Anyway, within a couple hours of downloading IJ EAP 11.1 and reading E. Goldin’s maven plugin post, I got ‘hello’ working from the IDE.
But I still cannot compile the app from the command line using mvn - I need to study the plugin config a bit more: the compiler cannot resolve the Kotlin class from within the Java class. Maybe it’s a maven compile-phase issue.
> mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mailchimp-kotlin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ mailchimp-kotlin ---
[INFO] Deleting /Users/petrovic/Projects/mailchimp-kotlin/target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ mailchimp-kotlin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/petrovic/Projects/mailchimp-kotlin/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ mailchimp-kotlin ---
[INFO] Compiling 1 source file to /Users/petrovic/Projects/mailchimp-kotlin/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/petrovic/Projects/mailchimp-kotlin/src/main/java/org/petrovic/mailchimp/App.java:[28,8] cannot find symbol
symbol : class ChimpUtils
location: class org.petrovic.mailchimp.App
[ERROR] /Users/petrovic/Projects/mailchimp-kotlin/src/main/java/org/petrovic/mailchimp/App.java:[28,27] cannot find symbol
symbol : class ChimpUtils
location: class org.petrovic.mailchimp.App
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.432s
[INFO] Finished at: Mon Feb 27 07:51:51 PST 2012
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project mailchimp-kotlin: Compilation failure: Compilation failure:
[ERROR] /Users/petrovic/Projects/mailchimp-kotlin/src/main/java/org/petrovic/mailchimp/App.java:[28,8] cannot find symbol
[ERROR] symbol : class ChimpUtils
[ERROR] location: class org.petrovic.mailchimp.App
[ERROR] /Users/petrovic/Projects/mailchimp-kotlin/src/main/java/org/petrovic/mailchimp/App.java:[28,27] cannot find symbol
[ERROR] symbol : class ChimpUtils
[ERROR] location: class org.petrovic.mailchimp.App
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
hth
Mark