Gradle Kotlin Plugin

I'm getting the same error, checking it now.

Goode one, Philipp! Made me add some useful changes to the plugin that will help trobelshooting similar problems.

  • If you get a new snapshot and run Gradle with "-i", Kotlin compile task will display its sourceDirs, outputDir and classpath.
  • I'll provide an extension to controll all options of K2JVMCompilerArguments (Andrey, is there a public Javadoc of this class available somewhere?)
  • Regarding this specific problem - the "javax.crypto" package isn't part of JDK's "rt.jar" and it appears the Kotlin compiler is not using "jce.jar" so it needs to be added explicitly. Could it be a bug?

You're welcome!

I’ve run the task with -d and this is where ‘sun.boot.class.path’ is set to

‘/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/netx.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/plugin.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/classes’

So the jce.jar is included. But I’m not sure, if this is used for the compileKotlin task too. How can I find out?

Run Gradle with "-i" flag, it'll print out the classpath used by compiler:

gradle -i --refresh-dependencies compileKotlin

Here’s what I get by running

gradle -i --refresh-dependencies :kotlin:kotlin-standalone:compileKotlin

with the test project where the “jce.jar” is added explicitly to the compilation classpath:

Running Kotlin compiler sourceDirs: * [/Users/evgenyg/Projects/gradle-plugins-test/kotlin/kotlin-standalone/src/main/kotlin/Bottles.kt] * [/Users/evgenyg/Projects/gradle-plugins-test/kotlin/kotlin-standalone/src/main/kotlin/HtmlBuilder.kt] * [/Users/evgenyg/Projects/gradle-plugins-test/kotlin/kotlin-standalone/src/main/kotlin/javaxCrypto.kt] outputDir: * [/Users/evgenyg/Projects/gradle-plugins-test/kotlin/kotlin-standalone/build/classes/main] classpath: * [/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/jce.jar] * [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.jetbrains.kotlin/kotlin-runtime/0.4.297/jar/89dac2725809603e44ea140b6d727684de79f8f8/kotlin-runtime-0.4.297.jar] * [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.jetbrains.kotlin/kotlin-stdlib/0.4.297/jar/9e7acc84ad525a8be3761b630fa63c38062cd6f6/kotlin-stdlib-0.4.297.jar] * [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.jetbrains.kotlin/kotlin-jdk-annotations/0.4.297/jar/829f396c4d5e9a38085d5de7a546ec76be6fa553/kotlin-jdk-annotations-0.4.297.jar] * [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.codehaus.groovy/groovy-all/2.0.5/jar/caef1126e5358bf1327e8b4381a827da9accbb47/groovy-all-2.0.5.jar] Compilation successful BUILD SUCCESSFUL

Yeah, it works with the explicit add. Here is the classpath

classpath: * [/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar] * [/home/phifty/.gradle/caches/artifacts-13/filestore/org.jetbrains.kotlin/kotlin-stdlib/0.4.297/jar/9e7acc84ad525a8be3761b630fa63c38062cd6f6/kotlin-stdlib-0.4.297.jar] * [/home/phifty/.gradle/caches/artifacts-13/filestore/com.googlecode.json-simple/json-simple/1.1.1/bundle/c9ad4a0850ab676c5c64461a05ca524cdfff59f1/json-simple-1.1.1.jar] * [/home/phifty/.gradle/caches/artifacts-13/filestore/org.jetbrains.kotlin/kotlin-runtime/0.4.297/jar/89dac2725809603e44ea140b6d727684de79f8f8/kotlin-runtime-0.4.297.jar] * [/home/phifty/.gradle/caches/artifacts-13/filestore/org.hamcrest/hamcrest-core/1.1/jar/860340562250678d1a344907ac75754e259cdb14/hamcrest-core-1.1.jar] * [/home/phifty/.gradle/caches/artifacts-13/filestore/junit/junit/4.10/jar/e4f1766ce7404a08f45d859fb9c226fc9e41a861/junit-4.10.jar]

Thanks for the fix. Let me know, if you need any more analysis.

Best regards
Philipp

With the refreshed dependencies, I get an exception now if I clean and re-build the project.

EXCEPTION: java.lang.IllegalArgumentException: trying to add non-existing file to classpath: /...project_home.../build/resources/main at org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment.addToClasspath(JetCoreEnvironment.java:173) at org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment.<init>(JetCoreEnvironment.java:94) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:142) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:54) at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:117) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:181) at org.jetbrains.jet.cli.jvm.K2JVMCompiler$exec.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)

Everything works fine again, if I manually create the directory again.

Oh, I used to filter the classpath entries and only include those that actually exist. But then decided not to filter them so that the info printout will display them all. I guess I need to bring the filtering back.

Hehe. This kind of mistake sounds familiar to me ;-)

Please, re-run Gradle using "--refresh-dependencies" again to get a new snapshot I've just deployed. Regarding the original problem - Andrey, should it be filed as an issue to Kotlin that it's not using JDK's jce.jar by default?

Works just fine. Thanks a lot!

Great, glad to hear it's Ok now. Will add it to documentation as well. Thanks again for your input.

Hey Evgeny,

Thanks for your help with all this. Unfortunately, I’m still struggling and I don’t know why. Here’s my complete gradle file:

final kotlinVersion = '0.4.297' buildscript {   repositories { maven { url 'http://evgenyg.artifactoryonline.com/evgenyg/repo/' }}   dependencies { classpath 'com.github.goldin.plugins.gradle:kotlin:0.2-SNAPSHOT'  } } apply plugin: 'kotlin' repositories {   mavenCentral()   mavenRepo url: 'http://repository.jetbrains.com/kotlin/' } // 4 - Kotlin compilation and runtime dependencies. dependencies {   compile "org.jetbrains.kotlin:kotlin-runtime:$kotlinVersion",            "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion",            "org.jetbrains.kotlin:kotlin-jdk-annotations:$kotlinVersion",            files( "${ System.getProperty( 'java.home' )}/lib/jce.jar" ) } sourceSets {   main {   kotlin {            srcDir 'src'   }   } }

I have one source file, in the src directory, as follows:

import java.util.TimeZone import java.text.SimpleDateFormat import java.util.Date val httpFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"; fun Date.asHttpFormatString(): String {   var sd = SimpleDateFormat(httpFormat);   sd.setTimeZone(TimeZone.getTimeZone("GMT")!!);   return sd.format(this); }

And when I attempt gradle compileKotlin, I get the following error:

:compileKotlin ERROR: /Users/jnichols/Developer/jonnichols.me/kt-test/src/dates.kt: (10, 10) Type mismatch: inferred type is jet.String? but jet.String was expected :compileKotlin FAILED

Note that this compiles perfectly fine within IntelliJ.

Can't say I know why it happens, had to add "!!" to make it compile with the plugin. Could be K2JVMCompilerArguments settings that are different between IDEA and Gradle task. Once I provide a way to read and write it it'll be easier to play with its values. Could anybody from Kotlin team shed some light on why this source

``

import java.util.TimeZone
import java.text.SimpleDateFormat
import java.util.Date

val httpFormat = “EEE, dd MMM yyyy HH:mm:ss zzz”;

fun Date.asHttpFormatString(): String {
  var sd = SimpleDateFormat(httpFormat);
  sd.setTimeZone(TimeZone.getTimeZone(“GMT”));
  return sd.format(this);
}


and this classpath

``

classpath:

  • [/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/jce.jar]
  • [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.jetbrains.kotlin/kotlin-runtime/0.4.297/jar/89dac2725809603e44ea140b6d727684de79f8f8/kotlin-runtime-0.4.297.jar]
  • [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.jetbrains.kotlin/kotlin-stdlib/0.4.297/jar/9e7acc84ad525a8be3761b630fa63c38062cd6f6/kotlin-stdlib-0.4.297.jar]
  • [/Users/evgenyg/.gradle/caches/artifacts-15/filestore/org.jetbrains.kotlin/kotlin-jdk-annotations/0.4.297/jar/829f396c4d5e9a38085d5de7a546ec76be6fa553/kotlin-jdk-annotations-0.4.297.jar]
causes this error
ERROR: /Users/evgenyg/Projects/gradle-plugins-test/kotlin/kotlin-standalone/src/main/kotlin/dates.kt: (12, 10) Type mismatch: inferred type is jet.String? but jet.String was expected

while it compiles Ok in IDEA? (build 123.72, Kotlin plugin v0.4.297)

Version "0.2-beta-5" depending on Kotlin "0.4.297" is released. Final "0.2" release is expected later this month with configurability/documentation improvements so let me know if you experience any problems with this version.

Hello, and thank you for your work on the Gradle Kotlin plugin!

I’ve been trying to figure out this issue regarding why the gradle plugin doesn’t seem to utilize the signature annotations from the kotlin-jdk-annotations jar.  Here’s what the situation looks like to me.  From experimenting with the kotlin-compiler jar it seems that the compiler automatically adds the kotlin-jdk-annotations jar to it’s classpath (based on relative directory structure).  The compiler’s -noJdkAnnotations flag is set then these external annotations are ignored by the compiler (even if the kotlin-jdk-annotations jar has been explicitly added to the classpath.

Setting the noJdkAnnotations option in the kotlin{} element to false in the build.gradle file seems to have no effect.  Also, from what I can see, the kotlin gradle plugin is hardcoding the noJdkAnnotations flag to true (see https://github.com/evgeny-goldin/gradle-plugins/blob/master/kotlin/src/main/groovy/com/github/goldin/plugins/gradle/kotlin/KotlinCompileTask.groovy).

Do you know why the noJdkAnnotations option is being hardcoded to true?  I don’t know if anyone is still following this thread so I will also open a YouTrack issue on the plugin with these observations

Thanks,
-Jon

Edit: Actually it looks like I can’t open an issue in YouTrack so hopefully you see this post :slight_smile:

Hello Jon, As the comment states it in the source code when noJdkAnnotations is hardcoded to "true": "Otherwise, Kotlin compiler attempts to locate the corresponding jar files" which means it fails otherwise (you can always fork the project, remove this assignment and build your version to see if it works better, pull requests are always appreciated). What I saw is that Kotlin compiler used by the plugin has several assumptions about how it is run and its main usage planned by Kotlin developers is a command-line invocation. So it starts exploring various disk folders looking for jar files which simply don't exist if Kotlin dependency is brought by a build tool such as Gradle. So I'd address this issue to Kotlin developers.

Yes, I need to request a new YouTrack open-source license for new people to be able to create an account. But I get e-mail notifications when this thread is updated so I see all replies here.

Is there an M5 compatible Gradle plugin available?

Yes, version "0.2.1-SNAPSHOT" uses Kotlin version "0.5.1".

I'm still struggling, still getting errors that are related to annotations. The build is part of this project (https://github.com/jonninja/node.kt) that I've just pushed. The build file is in core/build.gradle.

When I run it, I’m still seeing things like:

ERROR: /node.kt/core/src/node/crypto/Crypto.kt: (21, 5) Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type java.security.MessageDigest?

Though these compile fine within IDEA.

If you have any time and could take a look, it would be greatly appreciated.