Error: DefaultOperationDescriptor#2b878eea already available in Android Studio - gradle

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

Related

Gradle wrapper fails to find javafx on build, built-in gradle works okay on build

The issue is that executing gradle commands via the wrapper will cause the compileKotlin step to fail with different mentions that it is unable to find javafx-related classes/packages.
I'm setting up the whole project structure so that all the build system is not dependent on the IDE but rather relies on using the wrapper to execute all the build.
But executing a gradlew.bat build on the command line will fail with the mentioned errors. However, executing a "build" via the embedded Gradle in Intellij works. (attached pictures)
A few things to mention:
kotlin version 1.3.50 (latest version)
gradle version in wrapper properties is 5.6.2
Build failure pic:
Build working with Gradle from Intellij:
Build from Intellij button:
Gradle config in Intellij:
I have already tried plenty of suggestions mentioned on several topics related to this one (Invalidated caches + Restart, re-importing project, generating the wrapper again, all the usual solutions you will see for this issue). None of them worked, so the issue remains. I tried switching between versions of Gradle and running the wrapper again and that didn't work, it seems that version specified for the wrapper and the Gradle distribution it pulls down does not matter since the build fails with exactly the same error on all versions.
Note that this happened quite recently after an update of Intellij Idea from version 2019.2.2 to 2019.2.3, I really hope this isn't the root issue behind it.
This is not the only project with Gradle kotlin-dsl using javafx that is failing right now: even creating a new empty project via the tornadofx-plugin for Intellij and migrating it to the kotlin-dsl will yield the same results: compileKotlin task will fail. Besides that, several older projects with gradle kotlin-dsl that were building fine from the wrapper suddenly started out giving the same error.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import edu.sc.seis.launch4j.tasks.DefaultLaunch4jTask
plugins {
application
id("edu.sc.seis.launch4j") version "2.4.6"
kotlin("jvm") version "1.3.50"
}
group = "genericdesktopapp"
version = "1.0-SNAPSHOT"
application {
mainClassName = "root/RootKt"
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation(kotlin(module = "reflect", version = "1.3.50"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.3.0-RC")
implementation("org.slf4j:slf4j-api:1.7.21")
implementation("com.lmax:disruptor:3.3.4")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.6.2")
implementation("org.apache.logging.log4j:log4j-api:2.6.2")
implementation("org.apache.logging.log4j:log4j-core:2.6.2")
implementation("commons-io:commons-io:2.6")
implementation("org.apache.commons:commons-text:1.6")
implementation("com.github.salomonbrys.kodein:kodein:4.1.0")
implementation("commons-validator:commons-validator:1.6")
implementation("no.tornado:tornadofx:1.7.17")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.0")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.withType<DefaultLaunch4jTask> {
outfile = "GenericToolbox.exe"
mainClassName = "root.Root"
productName = "GenericToolbox"
}
I expect that when I run in the command line gradlew.bat build or ./gradlew build for it to complete normally and find the related classes from javafx, like it happens when using Intellij Gradle build command.
This issue should not even happen since I'm keeping everything at java-8, I know this issue is supposed to happen to versions beyond 8. I'm also seeing in the gradle caches the stdlib-jdk7 from kotlin, I have nowhere nothing related to jdk7 specified in my Intellij configurations or in the build script, so that is also something weird happening. (even cache reset made gradle pull it back in the cache, so I'm thinking it's probably the embedded kotlin compiler from gradle that is that version).
Edit: An easy way of reproducing it (just tested it right now).
Open a command line and create a new project with gradle kotlin dsl:
mkdir testproject
cd testproject
gradle init --dsl kotlin
On the project that was generated, run the gradlew.bat build or ./gradlew build and see the compileKotlin working okay and the build is successful.
On the same project, in the generated App.kt file, in the main function, add a simple val stage = Stage() (imported from javafx).
Run again the gradlew.bat build and see that it now fails since it doesn't find javafx.
I have managed to find a way around this issue, however, it's not a proper solution since I still haven't found the cause for why that was happening, but I'll post it in case anyone else will have this issue and maybe it will be helpful.
The solution is (weirdly enough) to specify the jdk version that gradle will use when running the commands through the wrapper:
gradlew.bat build -Dorg.gradle.java.home=---path-to-jdk---
I have checked my environment variables and the java home variable already points to that same location, so somehow I believe gradle doesn't find the java home and uses something embedded (which is most likely something above java 8) which produces that error. Running through the Intellij gradle works because it is using the embedded jdk in Intellij which is also java8, so that explains why they were working through the Intellij build button from the Gradle side-window.
If anyone finds the root cause or has some other suggestion, please, feel free to share your knowledge.

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

Custom Gradle plugin jar - adding transient dependencies to classpath

I have created a custom gradle plugin that has transient dependencies. The plugin is working fine and I am outputting the archives to a local maven repo, which again is all working fine. The output directory contains both the pom and jar files.
I want to be able to distribute the plugin between the projects without dependency on the local repo, and without setting up a remote private repo. The obvious choice here is to distibute the jar file between projects, however this requires me to then manually add the transient dependencies of the plugin to a project's classpath.
My questions is how can I distribute a gradle plugin as a jar and have it include transient dependencies without having to manually add those dependencies to a new projects classpath?
Without adding to the classpath I am seeing the following error:
Error:(4, 0) Unable to load class 'x'.
Possible causes for this unexpected error include: Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.).
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project. In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Run specific project using gradle

I have a Groovy application, I am using Gradle as my build tool. I have 2 seperate projects a Ratpack project with it's own build.gradle file and then a React project with it's own build.gradle file.
When I do ./gradlew run It builds my Ratpack project which in my Ratpacks build.gradle file has
compile project(':react-app')
In the dependencies closure.
Is there a way to just be able to run one of the projects for example ./gradlew runRatPack which stops the React project from being built?
If you can change the following line
compile project(':react-app') which states there is a Project Dependency to
compile name : 'react-app' - artifact dependency, then the project will try to pick the artifact from the repository instead of building the project.
Please let me know if the issue is addressed and this solves your issue.

Gradle build succeeds even though dependencies can't be downloaded

We are new to Gradle and dependency resolution. I am in the process of creating pom.xml files for all our internally-generated artifacts and want to set up a job in our Jenkins server to verify the dependencies are properly defined and not conflicting (i.e. LibA requires x-1.0.jar, LibB requires x-1.1.jar, and AppY requires both LibA and LibB).
As such, I've set up a dummy project in SVN that simply includes a bunch of our internal artifacts as dependencies. Following TTD, I intentionally included some errors in the declarations (i.e. group and name, but not version). Sure enough, those dependencies can't be found.
But when I run this build with gradle (i.e. gradle dependencies) it includes all the failure messages but still says the build succeeded! Not good!
How can I, using Gradle/Jenkins, set up an automated job that will verify all dependencies are found?
There is no built-in task that resolves all dependencies and fails if a dependency isn't found. (IDE tasks are graceful in case of missing dependencies.) But you can easily write your own:
task resolveDependencies {
doLast {
configurations.all { it.resolve() }
}
}
gradle dependencies by design displays Gradle project dependencies reporting (if applicable) if given dependency cannot be resolved (a red text FAILED next to an unresolved dependency). To get an error use some task that depends on resolving dependencies for given configuration(s) like gradle check.
Updated. Gradle is smart in determining if given tasks are required to be executed. Therefor in case there is no source files to compile (compilation requires dependent classes/JARs to be resolved) gradle check can notice that executing compileJava/compileTestJava tasks is not needed (tasks are skipped as up-to-date). You can force it by adding any Java source file into src/main/test (tests requires also production dependencies (from compile configuration)).
This is just a workaround, there is probably a better way to do that (and I hope someone else will present it here).

Resources