Is it possible to use Kotlin to develop a plugin for Eclipse? The project I'm working on uses Maven Tycho and OSGi.
To prevent misunderstandings, this is not about the Kotlin Eclipse Plugin, but about developing a custom plugin using the Kotlin language.
I added a dependency to the Kotlin stdlib in my pom.xml
, but that doesn't seem to be enough just yet.
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
Since there are a lot of potentially relevant files (MANIFEST.MF
, pom.xml
, ...) I thought it might be easier to just link the GitHub repo: https://github.com/Tornac/slr-toolkit/tree/kotlin/plugins/de.tudresden.slr.questionnaire.
Only the code in plugins/de.tudresden.slr.questionnaire
is mine, and I only care about adding Kotlin code to that particular plugin. My attempt to integrate Kotlin can be found on the kotlin
branch. All the changes can be found in this commit: https://github.com/Tornac/slr-toolkit/commit/18f8f6de3a35644ef1ae595024667f4bdd10b604
During compilation, the following error is briefly shown:
ERROR: Cannot access built-in declaration 'kotlin.Unit'. Ensure that you have a dependency on the Kotlin standard library (5, 14)
.
Kotlin:
// file: KtTest
package de.tudresden.slr.questionnaire
class KtTest {
fun doStuff() {
System.out.println("hello world, this is kt!");
}
}
Java:
// trying to call KtTest's method from Java
new KtTest().doStuff();
Stacktrace caused by calling doStuff():
java.lang.NoClassDefFoundError: de/tudresden/slr/questionnaire/KtTest
at de.tudresden.slr.questionnaire.QuestionnaireView$1.mouseDown(QuestionnaireView.java:78)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:192)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at de.tudresden.slr.app.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.ClassNotFoundException: de.tudresden.slr.questionnaire.KtTest cannot be found by de.tudresden.slr.questionnaire_0.2.6.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 29 more