Reputation: 995
I have a project that has both gradle (6.3) and gradlew. When I do a "./gradlew build", all is fine. But when I do "gradle build" I have the following error:
What went wrong:
A problem occurred evaluating root project ....
> Failed to apply plugin [id '...']
> Could not create an instance of type ....
> org.gradle.api.file.ProjectLayout.directoryProperty()Lorg/gradle/api/file/DirectoryProperty;
Any idea what could cause the wrapper to work OK and not gradle?
Thanks - C
Upvotes: 1
Views: 859
Reputation: 11963
./gradlew build
uses a different version of Gradle than what gradle build
uses. That's exactly the reason for the gradle wrapper: it will look at the contents of the file gradle/wrapper/gradle-wrapper.properties
to figure out which version of Gradle to use, and then automatically downloads and uses that Gradle version. The Gradle you have installed, version 6.3, is newer than the one used by the gradlew
(gradle wrapper) script. This is why gradle build
does not work: your build script is incompatible with this new gradle version, it only works with the older one used by the gradlew
script.
The error you see is caused by an incompatibility of your Gradle build script with a newer Gradle version. Let's look at the first part:
> Could not create an instance of type ....
> org.gradle.api.file.ProjectLayout.directoryProperty()Lorg/gradle/api/file/DirectoryProperty;
It tells you that Gradle is looking for a method directoryProperty
in the class ProjectLayout
. This member exists up to Gradle Version 5 (see https://docs.gradle.org/5.0/javadoc/org/gradle/api/file/ProjectLayout.html) but is no longer present in Gradle 6.3 (https://docs.gradle.org/current/javadoc/org/gradle/api/file/ProjectLayout.html). So the Gradle API changed, and your build script is no longer compatible.
The second part of the error:
> Failed to apply plugin [id '...']
tells you that this happened in the implementation of the plugin (given by the ...
in the id). This means that to fix the error with newer gradle versions, the plugin needs to be modified.
Upvotes: 2