Issue with Gradle and Gradlew - gradle

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

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

Related

Corda - Gradle Error With Quasar When Upgrading to Corda 4.3

I've updated my build.gradle file to Corda 4.3, however applying this plugin...
apply plugin: 'net.corda.plugins.quasar-utils'
...causes the following error when trying to refresh gradle...
A problem occurred evaluating root project 'template'.
> Failed to apply plugin [id 'net.corda.plugins.quasar-utils']
> Could not create an instance of type net.corda.plugins.QuasarExtension_Decorated.
> No signature of method: org.gradle.api.internal.provider.DefaultPropertyState.convention() is applicable for argument types: (java.lang.String) values: [co.paralleluniverse]
Any ideas what is causing this?
I had the same problem executing Corda 4.4 release. Basically you have to update your gradle version to recognize some dependencies in gradle.
First of all, execute the comand: gradle -version
After that, you have to update your gradle version according to the gradle version supported by your current Corda version. In my case, It is supported by gradle version 5.4.1. So, to execute an upgrade, try this: ./gradlew wrapper --gradle-version 5.4.1
Next, check again your gradle version using ./gradlew --version (in the CorDapp directory)
Finally, you can execute your task. So, in my case I would like to execute a test with heap dump allocating more memory and check an OOM. I execute the follow command:
./gradlew test -Dlog4j.configurationFile=../config/test/log4j2.xml -Dcapsule.jvm.args=["-Xmx10G","-Xms512m","-XX:+UseG1GC","-XX:+HeapDumpOnOutOfMemoryError"]
That is it!
Have you tried with gradle-5.4.1?
Source : https://www.corda.net/blog/corda-version-upgrade-guide/

org/jetbrains/kotlin/android/synthetic/idea/AndroidExtensions Gradle Model : Unsupported major.minor version 52.0

I am using the following setup:
Just updated Intellij to 2019.1.1
I converted my gradle project to use gradlew (ran $ gradle wrapper to generate gradlew in my root project)
Using Java 7
Then run/import the project in intellij to automatically detect it as a project
My IntelliJ is getting the error (in IntelliJ only):
org/jetbrains/kotlin/android/synthetic/idea/AndroidExtensions Gradle
Model : Unsupported major.minor version 52.0
But when I run the $ gradlew clean build in command line, it ran and build successfully
I disabled kotlin plugin of IntelliJ since I am not using it, it is just preventing me to build the project in IntelliJ.
Go to File > Settings > Plugins > Search 'kotlin':
After this, IntelliJ will restart. And your project will now be detected as gradle project

Gradle Plugin Test Project Build Failing

I downloaded the gradle plugin test project from their github here:
https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/customPlugin
I also updated gradle to latest (4.7).
When I gradle build the consumer project, I get the following build error:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'consumer'.
Could not resolve all artifacts for configuration ':classpath'.
Could not find org.gradle:customPlugin:1.0-SNAPSHOT.
Searched in the following locations:
file:/C:/Code/gradle/subprojects/docs/src/samples/customPlugin/repo/org/gradle/customPlugin/1.0-SNAPSHOT/maven-
metadata.xml
file:/C:/Code/gradle/subprojects/docs/src/samples/customPlugin/repo/org/gradle/customPlugin/1.0-SNAPSHOT/custom
Plugin-1.0-SNAPSHOT.pom
file:/C:/Code/gradle/subprojects/docs/src/samples/customPlugin/repo/org/gradle/customPlugin/1.0-SNAPSHOT/custom
Plugin-1.0-SNAPSHOT.jar
Required by:
project :
What's the issue here? I guess I don't understand gradle plugins enough. Does the plugin need to be built somehow? I have no 1.0-SNAPSHOT pat or anything of the sort, which seems to be where its looking.
Does the plugin need to be built somehow ?
Yes, at first, otherwise the consumer project won't find it.
Inside the plugin project, just run gradle uploadArchive
And then retry a gradle build inside the consumer project

Why is my shellscript execution of a gradle build behaving differently on jenkins than on cli?

When I perform ./gradlew build on command line, gradle downloads and unzips the correct wrapper dist version and continues to download dependencies and build the project.
However when I perform the same within a shellscript on jenkins, it only downloads the gradle wrapper dist zip and tells me there are no dependencies.
How come no dependencies are seen this time ?
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL in 9s
I have already (first) tried using the gradle plugin on jenkins, same result. ANDROID_HOME is the same and set, I am using the same user on the cli.
Java version 8, Gradle 4.1, Android 25, Android build-tools 26.0.2
When i let jenkins invoke a script holding this build command it does work, but not directly. (current quickfix)
Does anyone have an idea what is going wrong ?
It now works, I am not sure what changed to fix this other than the fact i have placed the commands in a function this time, but it is all working as desired.

Error: DefaultOperationDescriptor#2b878eea already available in Android Studio

Failed to complete Gradle Execution
When I try to Sync Gradle with Project Files, the error mentioned below appears
Android Studio version that I am using is 3.0.1, Gradle Build 4.1-all.zip
FYI, I have already tried ->Build->Clean Project and Invalidate Cache & Restart and one more thing is that there is no error in my code.
Message Error:
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
Error:Failed to complete Gradle execution.
Cause:
Operation org.gradle.tooling.internal.provider.events.DefaultOperationDescriptor#86028ba already available.
BUILD SUCCESSFUL in 8s
Information:1 error
Information:0 warnings
But When I try to Run on my Emulator
The error below appears
Message Error At Run Time
Information:Gradle tasks [:app:assembleDebug]
E:\Android Game App\app\build.gradle
Error:(1, 1) A problem occurred evaluating project ':Android Game App:app'.
Failed to apply plugin [id 'com.android.application']
Due to a limitation of Gradle new variant-aware dependency management, loading the Android Gradle plugin in different class loaders leads to a build error.
This can occur when the buildscript classpaths that contain the Android Gradle plugin in sub-projects, or included projects in the case of composite builds, are set differently.
To resolve this issue, add the Android Gradle plugin to only the buildscript classpath of the top-level build.gradle file.
In the case of composite builds, also make sure the build script classpaths that contain the Android Gradle plugin are identical across the main and included projects.
If you are using a version of Gradle that has fixed the issue, you can disable this check by setting android.enableBuildScriptClasspathCheck=false in the gradle.properties file.
To learn more about this issue, go to https://d.android.com/r/tools/buildscript-classpath-check.html.
Information:BUILD FAILED in 16s
Information:1 error
Information:0 warnings
Information:See complete output in console
Nothing found on Google! Any help would be highly encouraged???
The key to the problem is this line. Maybe due to a project.all in root build.gradle or you are using composite builds.
This can occur when the build script classpaths that contain the Android Gradle plugin in sub-projects,
or included projects in the case of composite builds, are set differently.
that mean in all yours build.gradle you have more than one this line
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:x.y.z"
}
}
what this means is that with the introduction of Android Gradle Plugin 3.Y.Z and the new way of handling dependencies,
if you mix in the same project 2 projects with different plugin version (one with a 2.3 and other with 3.0.1) you will get dragons while compiling.
And this error it's a way to force developer to check it and opt-out once detected and solved.
how to solve it, first ensure you don't use a android gradle plugin below 3.0.1 and use the new dependencies configurations, and add this property on every gradle.properties you have.
android.enableBuildScriptClasspathCheck=false
with that you can now compile
one example could be found at realm sample repo they use a allprojects block that include android gradle plugin on every module. and solve it adding previus gradle property at root gradle.properties

Resources