Intellij 2018.2: Not able to SYNC Gradle 1.9 projects - gradle

Unable to load class 'org.gradle.api.artifacts.component.ModuleComponentIdentifier'.
Possible causes for this unexpected error include:Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)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.

1.9 is a very old Gradle version. It is not supported by the latest IDE versions for Gradle projects importing. Please use more recent Gradle versions.

Related

Gradle's dependency cache may be corrupt in Intellij Idea

Today when I refresh the spring boot project in Intellij Idea IntelliJ IDEA 2022.1.1 (Ultimate Edition), show error like this:
Unable to find method ''org.gradle.api.tasks.SourceSetContainer org.gradle.api.plugins.JavaPluginExtension.getSourceSets()''
'org.gradle.api.tasks.SourceSetContainer org.gradle.api.plugins.JavaPluginExtension.getSourceSets()'
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
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.
I have already tried:
restart IDE
invalidate cache and restart IDE
stop gradle build process and restart IDE
remove the ./gradle/wrapper/dist folder
change the gradle version in gradle/wrapper folder
both did not fixed this problem, why did this happen? what should I do to fixed this problem? BTW, when I using this command ./gradlew clean :dolphin-post:dolphin-post-service:build -x test to build project in terminal:
➜ dolphin-post git:(master) ✗ ./gradlew clean :dolphin-post:dolphin-post-service:build -x test
Downloading https://services.gradle.org/distributions/gradle-7.4.1-all.zip
...............10%...............20%...............30%...............40%...............50%................60%...............70%...............80%...............90%...............100%
Welcome to Gradle 7.4.1!
Here are the highlights of this release:
- Aggregated test and JaCoCo reports
- Marking additional test source directories as tests in IntelliJ
- Support for Adoptium JDKs in Java toolchains
For more details see https://docs.gradle.org/7.4.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :dolphin-acientbay
/Users/xiaoqiangjiang/source/reddwarf/backend/retire
> Configure project :dolphin-post
/Users/xiaoqiangjiang/source/reddwarf/backend/retire/build.gradle'
> Configure project :dolphin-template
/Users/xiaoqiangjiang/source/reddwarf/backend/retiretemplate/build.gradle'
> Task :dolphin-common:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :dolphin-post:dolphin-post-service:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1m 58s
17 actionable tasks: 16 executed, 1 up-to-date
works fine.

Intellij Idea: Gradle sync cancelled even if it successful from command line

I am opening a working Gradle project in Idea, but it is failing to sync. In the sync window it says Sync cancelled. I tried changing proxy settings, project SDK, reboot, killing gradle daemon forcefully, but no luck
Solved the problem by changing Gradle JVM from settings.
In Maven project we can set project SDK, and it will be used for Maven build also.
But for Gradle we have to set it differently. Setting project SDK alone doesn't help as it is used only for project by Idea and not for Gradle.
Need to set the Gradle JVM to compatible JVM
Go to Settings
Search for Gradle under Build Tools
Set Gradle JVM to >=1.8

How do I force Gradle to get the most recent snapshot version of my package?

I have a Maven package I've hosted on GitHub package registry.
Whenever I make an update to the package I run mvn deploy to publish the changes, but if I simply run gradle install on the dependent application it doesn't seem to install the latest version of the package
(not sure if settings.xml is relevant to this question so I removed it, but it can be seen at the link to my previous question).
I had a similar issue with using the latest snapshot version of the package in another dependent, which was using Maven as the package manager/build tool instead of Gradle. That was resolved by checking a box to "always update snapshots" in Maven settings. I have checked the box in this project as well, but it doesn't seem to resolve the issue now.
What I have tried:
Invalidating cache and restarting IntelliJ
reimporting all gradle projects
deleting the dependency from my build.gradle and then reimporting projects and install, followed by adding it back and reimporting all projects and install
running ./gradlew build -x test --refresh-dependencies (test disabled because they were failing)
This is the log after I run gradle install:
4:07:08 PM: Executing task 'install'...
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar SKIPPED
> Task :install
BUILD SUCCESSFUL in 2s
3 actionable tasks: 1 executed, 2 up-to-date
4:07:10 PM: Task execution finished 'install'.
In my build.gradle I use the following syntax for my dependency (under dependencies):
compile('com.companyname:packagename:0.0.3-SNAPSHOT')
and this is what I have under repositories:
maven {
url "https://maven.pkg.github.com/companyname/packagename"
credentials {
username "TaylorBurke"
password "*****************"
}
}
Not sure if it is related, but when I go into my Maven settings to try and update the repository I get this error:
So there it is, I think I've included everything. Is it a configuration issue with Maven, Gradle, or IntelliJ?
Edit: because it has been suggested to close this question I am pointing out that the link to the other question does not address installing with Gradle, it simply addresses an error after running mvn deploy. I have already deployed the new package successfully and can get the new version from my other application. My problem is specific to gradle install. Even though the accepted answer mentions he had a similar problem using Gradle (but my problem is not with deploying either) he goes on to say that snapshot versions would provide a solution to the problem expressed, and I am already using a snapshot version in this package. That question is clearly quite different and not at all related to mine.
You have tried quite a few things with IntelliJ, but the problem happens when you run the build from the command line (./gradlew build). That should be a good indication that the problem is not with IntelliJ.
By default, Gradle will cache changing dependencies (e.g. SNAPHOST dependencies) for 24 hours. During that time, it will not ask the repository for newer versions. So if you publish a new version under the same name, Gradle might not see it for another day.
Using the --refresh-dependencies option will make Gradle ignore the cache, and thereby download the artifacts again.
You can also change the cache retention period through a ResolutionStrategy. You can also configure it to always check for changed dependencies if you like.
Read more about dynamic dependencies here: https://docs.gradle.org/current/userguide/dynamic_versions.html
If you are curious, the Gradle artifact cache is by default located in $USER_HOME/.gradle/caches/modules-2/files-2.1 (the numbers may be different depending on which version of Gradle you are using). This cache is unrelated to the one you mention in IntelliJ.
Also, the authentication error in the IntelliJ maven repository browser is because your credentials are in the Gradle configuration and not in IntelliJ. So this is also unrelated to Gradle.

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.

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