IntelliJ IDEA build.gradle.kts autocomplete not working - gradle

I have a strange problem that I was not able to find any solution so far.
I am quite new to gradle and set up a project using kotlin as the script language for my build-file.
Wherever I look, people seem to have comprehensive autocomplete capabilities in the build.gradle.kts file, but in my case, IntelliJ acts as if it doesn't have access to the sources.
No/very basic autocomplete, and only very basic syntax highlighting is happening.
For example if I click on the plugins` block (or any other block for that matter) to see the definition, IntelliJ tells me "Cannot find declaration to got to"
There is very little context-sensitive autocomplete:
I have read this answer about adding the -all distribution jar to the gradle-wrapper.properties file but it did not change anything. My gradle-wrapper.properties looks like this:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
I am using:
IntelliJ IDEA 2019.3.1 (Ultimate Edition)
Build #IU-193.5662.53, built on December 18, 2019
Runtime version: 11.0.5+10 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Linux 5.4.12-arch1-1
Memory: 1981M
Cores: 8
Gradle version is:
./gradlew -v
------------------------------------------------------------
Gradle 6.1
------------------------------------------------------------
Build time: 2020-01-15 23:56:46 UTC
Revision: 539d277fdba571ebcc9617a34329c83d7d2b259e
Kotlin: 1.3.61
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 13.0.1 (Oracle Corporation 13.0.1+9)
OS: Linux 5.4.12-arch1-1 amd64
I would appreciate any help in getting a little more joy and ease with my entry into the gradle world. :)

For me I found this error:
Caused by: org.gradle.api.GradleException: Spring Boot plugin requires Gradle 6.8.x, 6.9.x, or 7.x. The current version is Gradle 6.5.1
so changing Gradle to a newer version helped me!

Related

How does the Gradle wrapper determine which Groovy version it's using?

This question doesn't mention the wrapper.
OS is Linux Mint 18.3.
So for this project I get the following from the wrapper:
mike#M17A ~/software projects/eclipse-workspace/TM_Engine_Exp $ ./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: 11.0.4 (Ubuntu 11.0.4+11-post-Ubuntu-116.04.1)
OS: Linux 4.4.0-53-generic amd64
From the OS I get the following (NB I know this is irrelevant!):
mike#M17A ~ $ groovy -version
WARNING: An illegal reflective access operation has occurred
...
Groovy Version: 2.5.8 JVM: 11.0.4 Vendor: Ubuntu OS: Linux
(NB the warning here occurs if you use a JDK > 8: there's nothing you can do about it currently).
And I get the following for the system's Gradle version (again irrelevant):
mike#M17A ~ $ gradle -version
WARNING: An illegal reflective access operation has occurred
...
------------------------------------------------------------
Gradle 4.8.1
------------------------------------------------------------
...
Groovy: 2.4.12
...
But my build.gradle contains the following dependency currently:
apply plugin: 'groovy'
...
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.5.7'
...
My environment variable is:
GROOVY_HOME=/home/mike/.sdkman/candidates/groovy/current
I'm not sure how this came to be set. The files there are almost certainly configured to use 2.5.8, as far as I can work out.
So my question is: how is the wrapper choosing to use 2.5.4 and where am I going the find these Groovy language files?
Also, presumably the version in the dependency section of build.gradle applies only to my testing and building files (i.e. written by me in Groovy), and has nothing to do with Gradle's own build actions and other tasks?
NB I'm tempted to uninstall my system Gradle and my system Groovy, since they just confuse the issue, and just rely on using the wrapper. Is this a sensible idea?
Gradle comes bundled with Groovy and does not look at what other versions you have installed on your system. This is why you are seeing different Groovy versions across different Gradle versions. You cannot change this version as it is part of Gradle and likely won't work with any other versions. If you are curious, you can look in the "lib" folder in your Gradle distribution to see all third-party libraries to Gradle, including Groovy - just don't go fiddling around with them.
As you mention, having declared a compile dependency to Groovy in your build script makes that particular version used when compiling. This is generally the only thing you should care about. (By the way, compile is deprecated, and you should use implementation.)
I am not sure what your goal is, but I would highly recommend only using the Gradle wrapper scripts, which means you can uninstall the system installation of Gradle if you like. You can ignore the Groovy version on your system (or uninstall it if you are not using it elsewhere).

Gradle JVM Version vs JDK

I want to use JDK11 in Gradle for compiling my project without modifying JDK_HOME, which points to JDK10. I'm using JDK10 for most projects, but testing an upgrade to JDK11 in Gradle.
JAVA_HOME=C:\Program Files\Java\jdk-10.0.2
In /.gradle/gradle.properties I set the following property:
org.gradle.java.home=C:/Program Files/Java/jdk-11.0.3
when I run the command: gradle properties, I see the following line:
org.gradle.java.home: C:/Program Files/Java/jdk-11.0.3
but when I run the command: gradle -version, I see this, showing JVM is version 10:
------------------------------------------------------------
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: 10.0.2 ("Oracle Corporation" 10.0.2+13)
OS: Windows 10 10.0 amd64
Despite is saying JDK10 above, is it still compiling in JDK11 and JVM only means the Java version used to run the Gradle Daemon?
The version reported by gradle -version is the one of the client VM executing that command.
Normally, Gradle will otherwise use a daemon process to execute your build. That process will respect the org.gradle.java.home setting.
Note that you can also have a finer control on which Java executable is used for the different tasks in Gradle. See the documentation for details.

IDEA reports errors in build.gradle.kts while command line gradle run succeeds

I am using Kotlin DSL with Gradle build tool.
My gradle build works well both locally and on jenkins server when run from command line.
However IDEA complains and marks several items red with the following errors:
Cannot access class 'java.lang.Object'. Check your module classpath for missing or conflicting dependencies
None of the following functions can be called with the arguments supplied
I have tried all 3 options in project settings:
- Use default gradle wrapper
- Use gradle 'wrapper' task configuration
- Use local gradle distribuition
Result if pretty same
QUESTION: is something wrong in config, or is there a fix or workaround for that?
IntelliJ IDEA 2018.1.2 (Community Edition)
Build #IC-181.4668.68, built on April 24, 2018
JRE: 1.8.0_152-release-1136-b29 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-20-generic
.
Kotlin plugin: 1.2.41-release-IJ2018.1-1
.
Gradle 4.7
------------------------------------------------------------
Build time: 2018-04-18 09:09:12 UTC Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12 Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017 JVM: 1.8.0_171 (Oracle Corporation 25.171-b11) OS: Linux 4.15.0-20-generic amd64
UPD: #tweitzel you are right, it was incorrect SDK setting, thanks!
in my case I had set a jdk as File->Project Structure... -> Project->Project SDK
instead of setting the Kotlin SDK
after setting Kotlin SDK as Project SDK my build.gradle.kts errors disappeared

Using Kotlin version 1.2+, but still get compiler error about `use`

when running the gradlew build or gradlew install on my kotlin project, the following exception shows up in the console:
'use((T) -> R): R' is only available since Kotlin 1.2 and cannot be used in Kotlin 1.1.
Requires newer compiler version to be inlined correctly.
information:
the project is already configured to use Kotlin version 1.2.40.
the project seems to compile and run fine when i run it from my IDE (intelliJ)
what's wrong?
i ran into the same problem.
i updated update my Gradle version from 4.4.1 to 4.7 and then i could build my project with Gradle just fine.
if you are using the gradle wrapper, follow these steps:
visit the Gradle docs to find out what the latest version of Gradle is now.
in [project_root]/gradle/wrapper/gradle-wrapper.properties, use the latest Gradle version available for the distributionUrl property. for example, here is my gradle-wrapper.properties, using Gradle version 4.7:
#Fri Jun 02 20:20:27 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
Months later, I encountered the same problem with a projet which is not up to date (still Kotlin 1.1.60), which suddenly stopped being compilable.
I resolved it by using the last version of Gradle Kotlin plugin (1.3.0 as I write).

How to stop gradle from downloading every time

I have installed gradle in Ubuntu 16.04.
Here is the output for gradle -v
------------------------------------------------------------
Gradle 2.10
------------------------------------------------------------
Build time: 2016-01-26 15:17:49 UTC
Build number: none
Revision: UNKNOWN
Groovy: 2.4.5
Ant: Apache Ant(TM) version 1.9.6 compiled on July 8 2015
JVM: 1.8.0_101 (Oracle Corporation 25.101-b13)
OS: Linux 4.4.0-38-generic amd64
But even now, whenever I create a new project based on gradle v2.10, it downloads it and then builds the project. According to the tutorials, after installing it, I shouldn't need to download it again. What is the problem here?
you will have to replace url with local path like this
distributionUrl = file\:///e:/android/gradle-2.10-bin.zip
and comment
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
in gradle-wrapper.properties
I think you have two concepts mixed up:
A manual installation of gradle (gradle.bat / gradle.sh)
The gradle wrapper (gradlew.bat / gradlew.sh)
When you mention executing gradle -v this has absolutely no effect on the gradle wrapper. The wrapper works independently of any manually installed gradle versions.
Since you are referencing gradle being downloaded I assume you are discussing the gradle wrapper (gradlew). The wrapper will first check if it has downloaded the version previously by checking the cache stored under $GRADLE_USER_HOME so will only ever download each version once. Subsequent gradlew invocations will use the previously downloaded/unzipped installation.

Resources