Gradle JVM Version vs JDK - gradle

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.

Related

Gradle build fails with "org/eclipse/jgit/storage/file/FileRepositoryBuilder has been compiled by a more recent version of the Java"

Starting from today I cannot build my project anymore. There are no changes in it.
Looks like some Gradle dependency is recompiled with Java 11.
I'm using Java 8 and Gradle 4.10.
org/eclipse/jgit/storage/file/FileRepositoryBuilder has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Does anyone have the same problem?
./gradlew --version
------------------------------------------------------------
Gradle 4.10.3
------------------------------------------------------------
Build time: 2018-12-05 00:50:54 UTC
Revision: e76905e3a1034e6f724566aeb985621347ff43bc
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_292 (Private Build 25.292-b10)
OS: Linux 4.15.0-142-generic amd64
echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64/
./gradlew clean
FAILURE: Build failed with an exception.
* What went wrong:
org/eclipse/jgit/storage/file/FileRepositoryBuilder has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
I've changed the version of Gradle plug-in org.ajoberstar.grgit in build.gradle and it is working. The version before was 4.1.0. Now: 4.1.1
plugins {
id 'java'
id "org.ajoberstar.grgit" version "4.1.1"
}

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

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

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.

Cannot run gradle commands terminal

I am having an issue with gradle in my Android Studio project. Whenever i run any tasks on the command line: clean,assemble etc the only task that gets run is build. I am using the latest version of android studio. I also have a gradlew executable file. The same thing happens when i attempt to run tasks using that. I have tried re-installing gradle locally on my machine but the issue keeps persisting. Does anyone have any ideas?
operating system = Ubuntu 13.04
gradle -v
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
Build time: 2013-12-17 09:28:15 UTC
Build number: none
Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.7.0_51 (Oracle Corporation 24.45-b08)
OS: Linux 3.8.0-35-generic amd64
examples commands i am executing are 'gradle clean' 'gradle check' 'gradle compileLint' 'gradle compileLint'
I have also tried using the gradle wrapper './gradlew clean' etc
I am using openJdk as my java platform.

Resources