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.
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.
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.
properties in the project folder or in the C:\Users\Username. gradle. Please make sure that the name of file is "gradle.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With