Compile Kotlin sources with Gant?


#1

Hello everyone,

As you may be aware there’s a Kotlin plugin for Grifofn available at http://artifacts.griffon-framework.org/plugin/kotlin
Given that Kotlin M1 has just been released I wanted to update the plugin to the latest version, however I encountered a few problems.

You see, the Griffon build systm relies on Gant to compile sources,

Apparently Kotlin M1 requires an additional jar (jdk-headers.jar) to be available, if that jar is missing I get the following exception

Caused by: java.lang.IllegalArgumentException: jdkHeaders must be included for mode REGULAR at org.jetbrains.jet.lang.resolve.java.CompilerDependencies.<init>(CompilerDependencies.java:47) at org.jetbrains.jet.lang.resolve.java.CompilerDependencies.compilerDependenciesForProduction(CompilerDependencies.java:94) at org.jetbrains.jet.buildtools.core.BytecodeCompiler.env(BytecodeCompiler.java:52) at org.jetbrains.jet.buildtools.core.BytecodeCompiler.sourcesToDir(BytecodeCompiler.java:94)

However if the jar is added to the classpath I get another error, this time form Gant itself.
Caused by: java.lang.SecurityException: Prohibited package name: java.lang at org.codehaus.griffon.cli.support.GriffonRootLoader.loadClass(GriffonRootLoader.java:49) at com.intellij.openapi.application.PathManager.extractRoot(PathManager.java:307) at com.intellij.openapi.application.PathManager.getResourceRoot(PathManager.java:299) at org.jetbrains.jet.utils.PathUtil.getJarPathForClass(PathUtil.java:86) at org.jetbrains.jet.utils.PathUtil.getDefaultCompilerPath(PathUtil.java:36) at org.jetbrains.jet.utils.PathUtil.getAltHeadersPath(PathUtil.java:77) at org.jetbrains.jet.lang.resolve.java.CompilerDependencies.compilerDependenciesForProduction(CompilerDependencies.java:94) at org.jetbrains.jet.buildtools.core.BytecodeCompiler.env(BytecodeCompiler.java:52) at org.jetbrains.jet.buildtools.core.BytecodeCompiler.sourcesToDir(BytecodeCompiler.java:94)

On the previous plugin release it was enough to compile Kotlin source from Gant with

  ant.taskdef(resource: 'org/jetbrains/jet/buildtools/ant/antlib.xml',)   ant.kotlinc(            output: projectMainClassesDir,            src: kotlinSrc,            classpathref: classpathId)

Assuming all jars were in the classpath (as shown in https://github.com/griffon/griffon-kotlin-plugin/blob/master/griffon-app/conf/BuildConfig.groovy)

So. Is it possible to circumvent the requirements of jdk-headers or the SecurityException?

TIA
Andres


#2

Actually the jdkHeaders.jar is should not be on the class path, but rather on the special path for alternative library headers. Unfortunately, in the M1 version there is no way to alter this path, and teh only place searched for this jar is the lib/alt directory under the compiler installation.

We will fix this in the future version, and for now you can adopt the same approach the Maven plugin uses: just put the headers jar in the appropriate place.


#3

Thanks Andrey, in the end I bundled kotlinc M1 with the plugin and loaded the jars as explained in the Ant integration document. A new release of the griffon-kotlin plugin ahs been posted :-)

Cheers,
Andres

PD: keep it up with the good work!


#4

Great! Thanks