IntelliJ IDEA unable to resolve fine working gradle dependency - gradle

I'm currently working on a Kotlin project with Gradle (source code here). It's a Bukkit plugin which depends on a library I maintain (library source code here). When running ./gradlew assemble in a terminal, everything works fine and the build succeeds (log below).
$ ./gradlew assemble --console plain
> Task :compileKotlin
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: /home/axel/.gradle/caches/modules-2/files-2.1/com.github.axelrindle/PocketKnife/v1.3.0/b2303013bfd8e21c419f1d640ef374afc48e86af/PocketKnife-v1.3.0.jar: Library has Kotlin runtime bundled into it
> Task :compileJava NO-SOURCE
> Task :processResources
> Task :classes
> Task :inspectClassesForKotlinIC
> Task :jar
> Task :assemble
BUILD SUCCESSFUL in 5s
4 actionable tasks: 4 executed
But when working in IDEA, my library is the only one the IDE fails to resolve for whatever reason.
I've already tried the following steps:
Delete gradle/idea caches (~/.gradle/caches;.idea)
Reinstall IDEA
Delete IDEA config directory (.IdeaIC2019.1)
Reimport the project in IDEA
I've already read the following questions/answers, but none of them worked:
Getting Gradle dependencies in IntelliJ IDEA using Gradle build
Unable to resolve dependencies in IntelliJ IDEA 2018.1
Gradle dependencies not working in IntelliJ
IntelliJ won't recognize some imports from gradle project
Intellij: Gradle dependency not found
Also, my idea.log can be found here: https://pastebin.com/0Z5b3Wdp
Last but not least some version information:
IntelliJ IDEA 2019.1.3 (Community Edition)
Build #IC-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.18.0-21-generic
$ ./gradlew --version
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 12.0.1 (Oracle Corporation 12.0.1+12)
OS: Linux 4.18.0-21-generic amd64

After a lot of failed troubleshooting, I found out what the problem was. My library contained the bundled kotlin runtime, which was causing impossible to debug resolving issues with IDEA. I split up the project into multiple subprojects, where the actual api dependency does not bundle the kotlin runtime. This fixed my issues.

I just cloned your repository from https://github.com/axelrindle/Broadcaster-Plugin
In your build.gradle file you are referencing version 1.2.2 of your PocketKnife artefact, which does not exist in your GitHub. If you use an existing version like 1.2.1 IntelliJ can resolve the dependency.

Related

Issue with Gradle and Gradlew

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.

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

"unable to resolve class" error after upgrading gradle 3 to gradle 4

Grails version: 3.2.9
Gradle initial version: 3.4.1 (everything works fine with this version)
Gradle upgraded version:4.10.3
Plugin: org.grails.grails-gsp
When I run gradlew war after upgrading gradle version to 4.10.3 I start to get the following error during execution of compileGroovyPages task:
dashboard_gsp.groovy: 2: unable to resolve class com.abnd.CarStatusEnum
# line 2, column 1.
import com.abnd.CarStatusEnum
^
Location of class com.abnd.CarStatusEnum is src/main/groovy/com/abnd/CarStatusEnum in the same project where the build is being run and gradlew war task completes successfully with gradle version 3.4.1. However when I upgrade gradle version to 4.10.3 then I start to get this error. Same happens with gradle version 4.1.
1) Any clue what can be the problem ?
2) Is that a good idea to use gradle version 4.x.x or 5.x.x with grails version 3.x.x as with gradle 5.x.x I start to get even more issues as some grails plugins(like grails-gsp v3.3.2 which is latest stable version) use some features that have been deprecated in gradle 4.x.x and removed from gradle 5.x.x (see the error bellow)?
Failed to apply plugin [id 'org.grails.grails-gsp']
Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.
1) Any clue what can be the problem ?
Yes. The error message is a clue that the GSP compiler can't find the enum class. This is because our plugin isn't compatible with Gradle 4.10.3.
2) Is that a good idea to use gradle version 4.x.x or 5.x.x with
grails version 3.x.x
No. Those Gradle versions are not supported with the version of Grails you are using.
I hope that helps.

Groovy version inside Gradle

I have upgrade gradle on my local machine.
then i checked the version, it returned;
------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_171 (Oracle Corporation 25.171-b11)
the groovy version is ; 2.4.15.
And I want to upgrade the gradle to 4.10.2 in my spring boot project, But I am using gradle 2.5.0 in my project.
is it caused any problem?
can we use 2.5.0 or any other groovy version in gradle 4.10.2?
What does the gradle's groovy version on my local machine mean?
There will be no foreseeable problems. It's basically like this: Gradle utilizes Groovy to run it's tasks - and in those you have this Groovy version at disposal. In the end it's just the build tool -- it's supposed to do a proper job at isolating class-path/-loading.
The Groovy plugin in Gradle will take care to pick up the proper version from your compile-time dependencies. So unless you are doing things in your tasks or mess with configurations, you should be pretty safe.
Since you mentioned Spring Boot: be sure to pin your Groovy version with ext['groovy.version'] = '2.5.3' though, or else you end up with the problem described above due to the ways the Spring Boot plugin deals with dependencies.

Gradle compileGroovy java.lang.ExceptionInInitializerError

Here is the github repo: https://github.com/entrpn/gradle_plugin. You will need to manually create a folder "repo" at the root of the project since git doesn't add empty directories. That is where the generated files are supposed to go when running:
./gradlew uploadArchives
I am trying to write a simple gradle plugin following this tutorial https://afterecho.uk/blog/create-a-standalone-gradle-plugin-for-android-a-step-by-step-guide.html and when I get to the part where I am trying to create the local maven repo, I am not able to.
Problem: I am using the gradle wrapper command line:
./gradlew uploadArchives
and I receive the above error. Anyone know what I am doing wrong. Here is the log output:
Executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler in worker daemon.
16:20:23.624 [INFO] [org.gradle.workers.internal.WorkerDaemonServer] Exception executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler in worker daemon: java.lang.ExceptionInInitializerError.
16:20:23.636 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationWorkerRegistry] Worker root.2.3 completed (1 in use)
16:20:23.636 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
16:20:23.636 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':compileGroovy'
Thank you.
Ok I figured it out. Jason's answer gave me a clue. I opened terminal and ran ./gradlew --version and got this output:
Gradle 3.5-rc-2
Build time: 2017-03-27 15:56:23 UTC
Revision: ec63970cd167993d3dcda346a1d00a286a23b1c9
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_131 (Oracle Corporation 25.131-b11)
OS: Mac OS X 10.12.6 x86_64
So I noticed the Groovy version is 2.4.10 so I changed the gradle file to use this version, recompiled and the files were generated.
When I tried to run it I received the following error in addition to yours,
When I tried to run it I received the following error, "Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.4.7 and you are trying to load version 2.3.11"
I modified build.gradle and changed line 14 from
compile 'org.codehaus.groovy:groovy-all:2.3.11'
to
compile 'org.codehaus.groovy:groovy-all:2.4.7'

Resources