IntelliJ gradle - unknown properties

Viewed 2096

The error:

Build file 'C:\Users\Me\Dev\project\app\build.gradle' line: 21

  • What went wrong: A problem occurred evaluating root project 'app'. Could not get unknown property 'libraries' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

inside app.gradle

dependencies{
    compile libraries.my_lib
    deploy libraries.my_lib
}

inside project.gradle

ext.libraries = {
    my_lib:    'com.myCompany:my-lib:1.0.0'
}

inside pom.xml

<modules>
    <module>my-lib</modules>
</modules>

Pressing CTRL+Space in app.gradle's libaries. shows the my_lib library that may be autocompleted, but when compiling using gradle clean deploy, it fails and returns the message above.

This only happened after I updated the IDE to the latest IntelliJ.

1 Answers

ext defines extensions only for a project it was called in. In your case, libraries.my_lib is defined in project.gradle (I guess, it is build.gradle in project directory) and, thus, is not available in a different build file (app.gradle, which is again, I guess, is a build.gradle in app directory)) unless project is not a parent of app. Child projects have access to parent's properties, and that is the only way to share ext: projects should be related to each other.

BTW, you can define properties in gradle.properties file. There may be many of them, one for every project in your build. Placing one gradle.properties in the root of your build you apply its content to the root of your project tree, thus, making the properties available everywhere (the same applies to ext block of a root object, as it follows from the previous paragraph).

Related