Gradle Kotlin Plugin

Hi all, I made available a Gradle Kotlin plugin, allowing to compile Kotlin code and tests using Gradle. Put your Kotlin sources in "src/main/kotlin", tests in "src/test/kotlin", add the code below to your Gradle build and run "gradle compileKotlin compileTestKotlin build" ("build" dependency on Kotlin tasks will be added later).

buildscript {
  repositories { mavenRepo url: ‘http://evgenyg.artifactoryonline.com/evgenyg/repo/’ }
  dependencies { classpath   ‘com.github.goldin.plugins:kotlin:0.1.4-SNAPSHOT’   }
}

apply plugin: ‘kotlin’
repositories { mavenRepo url: ‘http://repository.jetbrains.com/kotlin/’ }

dependencies {
  compile ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’,
           …

  runtime ‘org.jetbrains.kotlin:kotlin-runtime:0.1-SNAPSHOT’,
           …
}

The plugin is in snapshot version right now. The release will be made for the next Kotlin milestone. If you can try it out till then and let me know of any issues that would help us to have it in a stable form before the first release.

Thanks!

I tried to compile a sample test project, but following your instructions, I get:

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘C:projectsTestbuild.gradle’ line: 19

  • What went wrong:
    A problem occurred evaluating root project ‘Test’.
    > No such property: runtime for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

I'm using Gradle 1.1, maybe you develop on a different version?

Digging a bit in your repo, I saw you’re using M1. Won’t be better to go with M2?

Hi, Can you paste your Gradle script here so it'll be possible to see where exactly the error was thrown? I'm using Gradle 1.1 and Kotlin 0.1-SNAPSHOT, that's a daily snapshot, not a milestone. Once M3 will be released the plugin version 0.1.4 will depend on it. What makes you think M1 is used?

I saw that version referred as M1 on this site, but maybe I made a mistake, I don't remember well... I thought that version, released on may, was M1 and version 0.1.2580, released on june, is M2.

Anyway, the gradle script is identical to your example:

buildscript {

  repositories { mavenRepo url: ‘http://evgenyg.artifactoryonline.com/evgenyg/repo/’ }

  dependencies { classpath   ‘com.github.goldin.plugins:kotlin:0.1.4-SNAPSHOT’   }

}

apply plugin: ‘kotlin’

repositories { mavenRepo url: ‘http://repository.jetbrains.com/kotlin/’ }

dependencies {

  compile ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’,

  runtime ‘org.jetbrains.kotlin:kotlin-runtime:0.1-SNAPSHOT’

}

and I put a simple main on src/main/kotlin/Main.kt:

fun void(args:Array<String>){   println("build with gradle!") }

I tried to build with gradle compileKotlin compileTestKotlin build

It was just a typo! You put a comma  after each dependency, but they are complete instruction. I just copy your code and did not notice it.

This is working fine now:


buildscript {

  repositories { mavenRepo url: ‘http://evgenyg.artifactoryonline.com/evgenyg/repo/’ }

  dependencies { classpath   ‘com.github.goldin.plugins:kotlin:0.1.4-SNAPSHOT’   }

}

apply plugin: ‘kotlin’

repositories { mavenRepo url: ‘http://repository.jetbrains.com/kotlin/’ }

dependencies {

  compile ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’

  runtime ‘org.jetbrains.kotlin:kotlin-runtime:0.1-SNAPSHOT’

}

Genie

Yes, comma is not needed in

dependencies {
  runtime “…”
  compile “…”
}

But it is needed in specifying multiple dependencies for the same configuration:

dependencies {
  runtime “…”
  compile “…”,
           “…”,
           “…”
}

Great! Glad it works now. I’ll post a reply in this thread when plugin version is released.

Good Evgeny! I look forward for it.

Release plugin version can be accessed by using:

buildscript {
  repositories {
  mavenRepo url: ‘http://repository.jetbrains.com/kotlin/
  mavenRepo url: ‘http://evgenyg.artifactoryonline.com/evgenyg/repo/
  }
  dependencies {
  classpath ‘com.github.goldin.plugins.gradle:kotlin:0.2-beta’
  }
}



It depends on Kotlin version “0.1.3395”. Later, version “0.2” of the plugin will be available on Maven Central as well.

When using the plugin, I'm getting some errors like this:

Type mismatch: inferred type is jet.String? but jet.String was expected

When calling some Java APIs. This despite the fact that within IntelliJ, things compile fine. I assume that this is because the compiler isn’t using the latest version of kotlin that has some information about standard java APIs, and which return nullable results.

Is this the case? Is there any way to have a plugin that uses a later version of the runtime?

It may be also that the build has not attached the files that contain that information (external annotation files).

How would I attach it to the build file? I have the std-lib:

dependencies {   compile 'org.jetbrains.kotlin:kotlin-stdlib:0.4.68'

}

Are there others I should be using?

JDK annotations come in kotlin-jdk-annotations.jar, but I'm not sure how one attaches them in the Gradle build.

Please, see this example, it shows how one can add compilation dependencies or change Kotlin version used by the plugin.

Forgive my gradle inexperience, but how do you add kotlin-jdk-annotations.jar to the build process?

I see this jar isn't published in Artifactory yet: http://repository.jetbrains.com/kotlin/org/jetbrains/kotlin/. Andrey, could you ask someone to publish it?

Will do.

Done for snapshot version, will be in the milestone soon

Good, thanks! Jon, the example below adds the "kotlin-jdk-annotations" to the compilation classpath, please post here any further problems you may experience.

apply plugin: ‘kotlin’


buildscript {
  repositories { maven { url ‘http://evgenyg.artifactoryonline.com/evgenyg/repo/’ }}
  dependencies {
  classpath ( ‘com.github.goldin.plugins.gradle:kotlin:0.2-SNAPSHOT’ ){ exclude group: ‘org.jetbrains.kotlin’ }
  classpath ‘org.jetbrains.kotlin:kotlin-compiler:0.1-SNAPSHOT’,
                  ‘org.jetbrains.kotlin:kdoc:0.1-SNAPSHOT’
  }
}


repositories { maven { url ‘http://repository.jetbrains.com/kotlin/’ }}
dependencies {
  compile ‘org.jetbrains.kotlin:kotlin-runtime:0.1-SNAPSHOT’,
           ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’,
           ‘org.jetbrains.kotlin:kotlin-jdk-annotations:0.1-SNAPSHOT’


}

'com.github.goldin.plugins.gradle:kotlin:0.2-SNAPSHOT' now depends on Kotlin v0.4.297.

Hello!

I have the problem, that the java packages javax.crypto.* cannot be found. Other java packages are ok. I guess there is some issue with the sourceCompatibility version. Here is my build.gradle

buildscript {   repositories { mavenRepo url: 'http://evgenyg.artifactoryonline.com/evgenyg/repo/' }   dependencies { classpath   'com.github.goldin.plugins.gradle:kotlin:0.2-SNAPSHOT'   } }

logging.captureStandardOutput LogLevel.INFO

apply plugin: ‘java’
apply plugin: ‘kotlin’

final version = ‘1.0’

repositories {
  mavenCentral()
  mavenRepo url: ‘http://repository.jetbrains.com/kotlin/
}

dependencies {
  compile group: ‘org.jetbrains.kotlin’, name: ‘kotlin-stdlib’, version: ‘0.4.297’
  compile group: ‘com.googlecode.json-simple’, name: ‘json-simple’, version: ‘1.1.1’

  runtime group: ‘org.jetbrains.kotlin’, name: ‘kotlin-runtime’, version: ‘0.4.297’

  testCompile group: ‘junit’, name: ‘junit’, version: ‘4.+’
}

test.dependsOn compileKotlin
test.dependsOn compileTestKotlin


Does anyone have ideas?

Best regards
Philipp