# Gradle Kotlin Plugin

**URL:** <https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909>\
**Category:** Uncategorized\
**Created:** [August 17, 2012, 10:40am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909 "2012-08-17T10:40:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [August 17, 2012, 10:40am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/1 "2012-08-17T10:40:11Z")

</div>

Hi all, I made available a [Gradle Kotlin plugin](http://evgeny-goldin.com/wiki/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](http://evgeny-goldin.org/youtrack/issue/gp-34) later).

buildscript {  
 &nbsp;&nbsp;repositories { mavenRepo url: ‘[http://evgenyg.artifactoryonline.com/evgenyg/repo/](http://evgenyg.artifactoryonline.com/evgenyg/repo/)’ }  
 &nbsp;&nbsp;dependencies { classpath &nbsp;&nbsp;‘com.github.goldin.plugins:kotlin:0.1.4-SNAPSHOT’ &nbsp;&nbsp;}  
}  
   
apply plugin: ‘kotlin’  
repositories { mavenRepo url: ‘[http://repository.jetbrains.com/kotlin/](http://repository.jetbrains.com/kotlin/)’ }  
   
dependencies {  
 &nbsp;&nbsp;compile ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;…

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

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](http://evgeny-goldin.org/youtrack/issues/gp?q=%23%7B%27kotlin%27+plugin%7D+) of any issues that would help us to have it in a stable form before the first release.

Thanks!

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [September 4, 2012, 8:38pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/2 "2012-09-04T20:38:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [September 4, 2012, 9:03pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/3 "2012-09-04T21:03:13Z")

</div>

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](https://github.com/evgeny-goldin/gradle-plugins/blob/722ffcbeada45057937df52e837e954a86e79305/build.gradle#L110) and Kotlin [0.1-SNAPSHOT](https://github.com/evgeny-goldin/gradle-plugins/blob/722ffcbeada45057937df52e837e954a86e79305/build.gradle#L3), 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?

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [September 4, 2012, 9:34pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/4 "2012-09-04T21:34:29Z")

</div>

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 {
> 
> &nbsp;&nbsp;repositories { mavenRepo url: ‘[http://evgenyg.artifactoryonline.com/evgenyg/repo/](http://evgenyg.artifactoryonline.com/evgenyg/repo/)’ }
> 
> &nbsp;&nbsp;dependencies { classpath &nbsp;&nbsp;‘com.github.goldin.plugins:kotlin:0.1.4-SNAPSHOT’ &nbsp;&nbsp;}
> 
> }
> 
> apply plugin: ‘kotlin’
> 
> repositories { mavenRepo url: ‘[http://repository.jetbrains.com/kotlin/](http://repository.jetbrains.com/kotlin/)’ }
> 
> dependencies {
> 
> &nbsp;&nbsp;compile ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’,
> 
> &nbsp;&nbsp;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\>){ &nbsp;&nbsp;println("build with gradle!") }

I tried to build with **gradle compileKotlin compileTestKotlin build**

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [September 4, 2012, 10:04pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/5 "2012-09-04T22:04:44Z")

</div>

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

This is working fine now:

> buildscript {
> 
> &nbsp;&nbsp;repositories { mavenRepo url: ‘[http://evgenyg.artifactoryonline.com/evgenyg/repo/](http://evgenyg.artifactoryonline.com/evgenyg/repo/)’ }
> 
> &nbsp;&nbsp;dependencies { classpath &nbsp;&nbsp;‘com.github.goldin.plugins:kotlin:0.1.4-SNAPSHOT’ &nbsp;&nbsp;}
> 
> }
> 
> apply plugin: ‘kotlin’
> 
> repositories { mavenRepo url: ‘[http://repository.jetbrains.com/kotlin/](http://repository.jetbrains.com/kotlin/)’ }
> 
> dependencies {
> 
> &nbsp;&nbsp;compile ‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’
> 
> &nbsp;&nbsp;runtime ‘org.jetbrains.kotlin:kotlin-runtime:0.1-SNAPSHOT’
> 
> }

Genie

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [September 4, 2012, 10:55pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/6 "2012-09-04T22:55:35Z")

</div>

Yes, comma is not needed in

**dependencies {**  
 **&nbsp;&nbsp;runtime “…”**  
 **&nbsp;&nbsp;compile “…”**  
**}**

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

**dependencies {**  
 **&nbsp;&nbsp;runtime “…”**  
 **&nbsp;&nbsp;compile “…”,**  
**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;“…”,**  
**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;“…”**  
**}**

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

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [September 5, 2012, 7:22am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/7 "2012-09-05T07:22:31Z")

</div>

Good Evgeny! I look forward for it.

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [September 25, 2012, 10:55pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/8 "2012-09-25T22:55:54Z")

</div>

Release plugin version can be accessed by using:

**buildscript {**  
 **&nbsp;&nbsp;repositories {**  
 **&nbsp;&nbsp;mavenRepo url: ‘[http://repository.jetbrains.com/kotlin/](http://repository.jetbrains.com/kotlin/)’**  
 **&nbsp;&nbsp;mavenRepo url: ‘[http://evgenyg.artifactoryonline.com/evgenyg/repo/](http://evgenyg.artifactoryonline.com/evgenyg/repo/)’**  
 **&nbsp;&nbsp;}**  
 **&nbsp;&nbsp;dependencies {**  
 **&nbsp;&nbsp;classpath ‘com.github.goldin.plugins.gradle:kotlin:0.2-beta’**  
 **&nbsp;&nbsp;}**  
**}**

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

---

<div class="post-metadata">

**Author:** ![steamstreet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/steamstreet/32/1529_2.png) [@steamstreet](https://discuss.kotlinlang.org/u/steamstreet)\
**Post date:** [December 7, 2012, 7:59am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/9 "2012-12-07T07:59:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [December 7, 2012, 9:53am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/10 "2012-12-07T09:53:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![steamstreet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/steamstreet/32/1529_2.png) [@steamstreet](https://discuss.kotlinlang.org/u/steamstreet)\
**Post date:** [December 7, 2012, 6:24pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/11 "2012-12-07T18:24:44Z")

</div>

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

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

}

Are there others I should be using?

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [December 7, 2012, 6:59pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/12 "2012-12-07T18:59:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [December 7, 2012, 7:05pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/13 "2012-12-07T19:05:24Z")

</div>

Please, see [this example](https://github.com/evgeny-goldin/gradle-plugins/issues/5), it shows how one can add compilation dependencies or change Kotlin version used by the plugin.

---

<div class="post-metadata">

**Author:** ![steamstreet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/steamstreet/32/1529_2.png) [@steamstreet](https://discuss.kotlinlang.org/u/steamstreet)\
**Post date:** [December 7, 2012, 9:04pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/14 "2012-12-07T21:04:34Z")

</div>

Forgive my gradle inexperience, but how do you add _kotlin_-_jdk_-_annotations_.jar to the build process?

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [December 7, 2012, 9:51pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/15 "2012-12-07T21:51:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [December 10, 2012, 9:04am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/16 "2012-12-10T09:04:57Z")

</div>

Will do.

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [December 10, 2012, 11:16am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/17 "2012-12-10T11:16:06Z")

</div>

Done for snapshot version, will be in the milestone soon

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [December 10, 2012, 12:44pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/18 "2012-12-10T12:44:33Z")

</div>

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 {  
 &nbsp;&nbsp;repositories { maven { url ‘[http://evgenyg.artifactoryonline.com/evgenyg/repo/](http://evgenyg.artifactoryonline.com/evgenyg/repo/)’ }}  
 &nbsp;&nbsp;dependencies {   
 &nbsp;&nbsp;classpath ( ‘com.github.goldin.plugins.gradle:kotlin:0.2-SNAPSHOT’ ){ exclude group: ‘org.jetbrains.kotlin’ }  
 &nbsp;&nbsp;classpath ‘org.jetbrains.kotlin:kotlin-compiler:0.1-SNAPSHOT’,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;‘org.jetbrains.kotlin:kdoc:0.1-SNAPSHOT’  
 &nbsp;&nbsp;}  
}  
  
   
repositories { maven { url ‘[http://repository.jetbrains.com/kotlin/](http://repository.jetbrains.com/kotlin/)’ }}  
dependencies {  
 &nbsp;&nbsp;compile ‘org.jetbrains.kotlin:kotlin-runtime:0.1-SNAPSHOT’,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;‘org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT’,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; **‘org.jetbrains.kotlin:kotlin-jdk-annotations:0.1-SNAPSHOT’**  
  
   
}

---

<div class="post-metadata">

**Author:** ![Genie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/genie/32/1596_2.png) [@Genie](https://discuss.kotlinlang.org/u/Genie)\
**Post date:** [December 10, 2012, 9:46pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/19 "2012-12-10T21:46:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![phifty](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phifty/32/1569_2.png) [@phifty](https://discuss.kotlinlang.org/u/phifty)\
**Post date:** [December 11, 2012, 4:48pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909/20 "2012-12-11T16:48:45Z")

</div>

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

```kotlin
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

[Next page](https://discuss.kotlinlang.org/t/gradle-kotlin-plugin/909.md?page=2)
