# Kotlin DSL syntax error for build.gradle.kts

**URL:** <https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944>\
**Category:** Uncategorized\
**Created:** [October 11, 2017, 1:53am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944 "2017-10-11T01:53:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanzhiding](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@hanzhiding](https://discuss.kotlinlang.org/u/hanzhiding)\
**Post date:** [October 11, 2017, 1:53am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/1 "2017-10-11T01:53:14Z")

</div>

I currently using intellij v2017.2.5 community edition. The editor does not recognize kotlin DSL syntax in the build.gradle.kts. E.g editor flagged out errors such as unresolved reference plugin when I use the plugin function, such as shown below

# content of my build.gradle.kts

apply{  
plugin(“java”) \<–unresolved reference plugin  
}  
task(“testing”){ \<–unresolved reference task  
doLast{ \<–unresolved reference doLast  
println(“hello”) \<–the editor recognized println api  
}

}

How do I configure the editor to recognize the kotlin DSL syntax?

Note that i configure my project to use local gradle distribution, not gradle wrapper.

Note: I am able to execute this build.gradle.kts successfully using command prompt, which show that the kotlin syntax I using is correct.

---

<div class="post-metadata">

**Author:** ![Antonel.Ernest.Pazargic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/antonel.ernest.pazargic/32/3608_2.png) [@Antonel.Ernest.Pazargic](https://discuss.kotlinlang.org/u/Antonel.Ernest.Pazargic)\
**Post date:** [October 11, 2017, 4:48am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/2 "2017-10-11T04:48:33Z")

</div>

Hi,

I think the syntax of the kts gradle build file is not correct. It is correct for the groovy based script.

Try the following

```
plugins {
    java
}

tasks {
    "testing" {
        println(“hello”)
    }
}

```

Test it with

> ./gradlew testing

Kr

Tony

---

<div class="post-metadata">

**Author:** ![hanzhiding](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@hanzhiding](https://discuss.kotlinlang.org/u/hanzhiding)\
**Post date:** [October 11, 2017, 5:21am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/3 "2017-10-11T05:21:31Z")

</div>

Hi Antonel,

Great thanks for your reply. I place your sample code, still the intellij editor displays **unresolved reference: plugins** error (among all other syntax errors) .  
Maybe syntax is correct, but the editor is not configured to recognize it. Hence Is there something i need to do to configure for the intellij editor?

\*Note that I did not execute using gradlew, cause I prefer using the local distribution of the gradle (which I download from gradle official website), unless executing the gradlew can help intellij editor to recognize the kotlin dsl.

---

<div class="post-metadata">

**Author:** ![Antonel.Ernest.Pazargic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/antonel.ernest.pazargic/32/3608_2.png) [@Antonel.Ernest.Pazargic](https://discuss.kotlinlang.org/u/Antonel.Ernest.Pazargic)\
**Post date:** [October 11, 2017, 7:37pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/4 "2017-10-11T19:37:35Z")

</div>

Hi hanzhiding,

I just recently started to play a bit with the gradle kotlin DSL and I created a project poi DSL.  
You can clone it locally and see if this works for you.  
[https://github.com/jtonic/dsl-poi](https://github.com/jtonic/dsl-poi)  
For me it works w/o any issues with IntelliJ Idea 2017.2.5 (2017.3 EAP) and latest version of kotlin stdlib and idea plugin (1.1.51). Gradle version: 4.2.1.

Can you tell me the version for:

1. IntelliJ Idea
2. IntelliJ Idea kotlin plugin
3. Gradle
4. kotlin version in gradle.build.kts

Kind regards.

---

<div class="post-metadata">

**Author:** ![Antonel.Ernest.Pazargic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/antonel.ernest.pazargic/32/3608_2.png) [@Antonel.Ernest.Pazargic](https://discuss.kotlinlang.org/u/Antonel.Ernest.Pazargic)\
**Post date:** [October 11, 2017, 8:28pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/5 "2017-10-11T20:28:48Z")

</div>

I did another try.  
On my system I had install **gradle version 3.4.1 (configured with GRADLE\_HOME)**.  
When I ran the gradle script with it, it failed.  
_Moreover when the gradle wrapper was quite old the gradle.build.kts was full of red lines, and running the application lead to an error._

As soon as I updated the gradle on my machine to latest **4.2.1** all is fine in Idea, gradlew and gradle.

The version of gradle is extremely important. Try to use the latest one. Moreover I remembered I read somewhere that gradle v 4.0 have the issue you are currently facing.

I suppose you use the IntelliJ Idea 2016.1.x or recent.

Note: Even it is an warning I personally took it very seriously. Quite ofter idea warns the version of its kotlin plugin and project one (configured in gradle or maven) is not the same.

I noticed the latest kotlin dsl gradle DSL (built in the latest gradle - 4.2.1) comes with kotlin 1.1.50.  
In my project on the github the gradle.build.kts based one is 1.1.51. Modify it to 1.1.50 and the warn should vanish.

Kr

Tony

---

<div class="post-metadata">

**Author:** ![hanzhiding](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@hanzhiding](https://discuss.kotlinlang.org/u/hanzhiding)\
**Post date:** [October 12, 2017, 3:58am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/6 "2017-10-12T03:58:28Z")

</div>

Hi,

Thanks for your reply and assistance!  
Currently, I am already using the below

1. Intellij IDEA 2017.25
2. Intellij Idea kotlin plugin (1.1.51-release-IJ2017.2-1)
3. Gradle 4.2.1
4. kolin version in gradle.build.kts? I not sure what this mean. I did not configure anything for this.  
Note: I configure Intellij to use my local distribution of gradle 4.2.1, and I did not use gradle wrapper at all.

I have reduced the content of my gradle.build.kts to only 3 lines as shown below

plugins{  
java  
}

but still the plugins and java words are in red, meaning unrecognized. Not sure why

Extra Info: My application source codes is actually java source code, not kotlin source codes.

---

<div class="post-metadata">

**Author:** ![Antonel.Ernest.Pazargic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/antonel.ernest.pazargic/32/3608_2.png) [@Antonel.Ernest.Pazargic](https://discuss.kotlinlang.org/u/Antonel.Ernest.Pazargic)\
**Post date:** [October 12, 2017, 7:48pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/7 "2017-10-12T19:48:56Z")

</div>

Hi,

It is strange. I use the same versions as you and for me it works.  
I created a new gradle kotlin dsl project with the **_gradle 4.2.1 install on my system_** , and this project also works like a charm. the command i ran was

> gradle run

You can clone is from [https://github.com/jtonic/gradledsl](https://github.com/jtonic/gradledsl)

If this project doesn’t work for you as well I recommend to **_Invalidate and Restart project_**. I hope this will help you.

Kr

Tony

---

<div class="post-metadata">

**Author:** ![hanzhiding](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@hanzhiding](https://discuss.kotlinlang.org/u/hanzhiding)\
**Post date:** [October 14, 2017, 6:54am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/8 "2017-10-14T06:54:54Z")

</div>

Hi, Thanks!

By invalidate cache and delete away the .gradle folder in my user folder and boom! the error gone. Thanks Antonel for your patient great help!!!

---

<div class="post-metadata">

**Author:** ![Antonel.Ernest.Pazargic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/antonel.ernest.pazargic/32/3608_2.png) [@Antonel.Ernest.Pazargic](https://discuss.kotlinlang.org/u/Antonel.Ernest.Pazargic)\
**Post date:** [October 14, 2017, 9:28am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/9 "2017-10-14T09:28:51Z")

</div>

Hi,

I am glad it works for you in the end.  
I am sure Jetbrains Dev Team will improve the support of kotlin based (build.gradle.kts) gradle project.

For me build.gradle.kts is better than the vanilla gradle.build in terms that it is type safe - this leads to a better IDE support.  
Of course **_Gradle Kotlin DSL_** ([GitHub - gradle/kotlin-dsl-samples: Samples builds using the Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl)) is a new project, so it expected to have some rough edges. But surely they will be addressed by the kt/gradle teams and community .

Kr

Antonel

---

<div class="post-metadata">

**Author:** ![render1980](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/render1980/32/4256_2.png) [@render1980](https://discuss.kotlinlang.org/u/render1980)\
**Post date:** [October 24, 2017, 1:50pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/10 "2017-10-24T13:50:17Z")

</div>

Had the same problem and the same versions of:

- IntellijIdea 2017.25
- IntellijIdea kotlin plugin (1.1.51-release-IJ2017.2-1)
- Gradle 4.2.1
- kotlin version: 1.1.51 (JRE 1.8.0\_131-b11)

Solution is `rm -r ~/.gradle`. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![sithys](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sithys/32/4635_2.png) [@sithys](https://discuss.kotlinlang.org/u/sithys)\
**Post date:** [January 9, 2018, 5:16am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/11 "2018-01-09T05:16:33Z")

</div>

I am seeing this error too. Here are my steps for reproduction:

Create new project  
Select Gradle (Kotlin DSL)  
Uncheck Java  
Check Kotlin (Java)  
Fill out the artifact/group/version stuff  
Use all default options  
Click create  
Double click build.gradle.kts to view the file  
Tons of red text appears in the file

I ran “check for updates” in IntelliJ before doing this. Ubuntu 16.04 LTS

---

<div class="post-metadata">

**Author:** ![Xerus](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/xerus/32/4499_2.png) [@Xerus](https://discuss.kotlinlang.org/u/Xerus)\
**Post date:** [January 21, 2018, 11:18am UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/12 "2018-01-21T11:18:04Z")

</div>

I’m also having this issue. Not even deleting my .gradle folder helped - still everything red

---

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [February 8, 2018, 5:54pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-syntax-error-for-build-gradle-kts/4944/13 "2018-02-08T17:54:06Z")

</div>

Using the currently stable versions (IntelliJ IDEA 2017.3.4, Gradle 4.5.1 and Kotlin 1.2.21) on Windows 10, I was able to resolve it by following these steps:

- Exit IDEA.
- If needed, update the Gradle wrapper. Repeat the following command until Gradle says it is up to date: `./gradlew wrapper`
- Delete folder `.gradle`
- Start IDEA.

It still worked after I restarted IDEA.
