Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ gradle - unknown properties

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.

like image 486
theAnonymous Avatar asked Nov 03 '17 09:11

theAnonymous


People also ask

How do I create a Gradle properties file in IntelliJ?

In the Project tool window, right-click the project and from the context menu, select New | File. In the New File dialog, enter gradle. properties as a filename and click OK. Open the created file in the editor and add the VM options you need.

Where is Gradle settings in IntelliJ?

We can get to the settings from the Gradle Tool Window, or from the usual Settings/Preferences dialog (⌘, (macOS), or Ctrl+Alt+S (Windows/Linux)) and navigating to Build, Execution, Deployment | Build Tools | Gradle.

Where can I find Gradle properties?

properties in the project folder or in the C:\Users\Username. gradle. Please make sure that the name of file is "gradle.


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).

like image 85
madhead - StandWithUkraine Avatar answered Oct 08 '22 08:10

madhead - StandWithUkraine