Search code examples
gradleintellij-ideagradle-kotlin-dslbuildsrc

Unresolved reference JavaVersion in gradle buildSrc IntelliJ


I am facing a problem with two existing gradle projects that worked fine a couple of months ago but that show now an annoying error in the buildSrc folder, where I use the org.gradle.api.JavaVersion constant.

The project compiles correctly and is imported to IntelliJ. I can also run it so I guess everything is working but of course I don't like to get an error thrown into my face ;)

Here are both example projects:

  1. https://github.com/Quillraven/Quilly-s-Adventure
  2. https://github.com/Quillraven/Dark-Matter

They are both a multi-project with a core, desktop and android project. In both projects I use a buildSrc folder to define the versions in a common place for the entire project.

For whatever reason, IntelliJ is now showing an error "unresolved reference JavaVersion" in the Dependencies.kt/versions.kt file.

enter image description here

The build.gradle.kts of the buildSrc folder looks like this:

plugins {
    `kotlin-dsl`
}

repositories {
    jcenter()
}

Does anyone know how to get rid of this error? Is it an IntelliJ issue or something else? Or is the issue on my end ?


Solution

  • This is an Intellij IDEA 2020.2 bug: https://youtrack.jetbrains.com/issue/KT-40683. Dependencies are unresolved in the buildSrc module, when you also have an Android module in the project.

    As a possible workaround, please use IDEA 2020.1.