Cannot run gradle commands terminal - gradle

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.

Related

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

Unable to add gradle wrapper task to old project due to, version too old error

I need assistance to add a wrapper to an old gradle (v2.12) project, but I'm unable to run the wrapper tasks due to the following error:
Failed to apply plugin [class 'fi.jasoft.plugin.GradleVaadinPlugin']
Your gradle version (4.2.1) is too old. Plugin requires Gradle 2.0+
According to the error, I need to upgrade my gradle version, yet I have version 4.2.1 installed locally. Is there anyway to run the wrapper task with a specific version?
Gradle 4.2.1
Build time: 2017-10-02 15:36:21 UTC
Revision: a88ebd6be7840c2e59ae4782eb0f27fbe3405ddf
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_40 (Oracle Corporation 25.40-b25)
OS: Mac OS X 10.12.6 x86_64
Edit:
Tried using --gradle-version
| => gradle wrapper --gradle-version 2.12
Configure project :
Root version lmichelson
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at build_an2u3e8kk42wdypa8wwdzfqcs$_run_closure6.doCall(/projects/maia/build.gradle:240)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
FAILURE: Build failed with an exception.
Where:
Script '/projects/maia/webapp/vaadin.plugin.0.10.7' line: 79
What went wrong:
A problem occurred evaluating script.
Failed to apply plugin [class 'fi.jasoft.plugin.GradleVaadinPlugin']
Your gradle version (4.2.1) is too old. Plugin requires Gradle 2.0+
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
BUILD FAILED in 2s
Thanks to the link and answer from #Opal, I solved the issue by
Installing SDKMAN
Downgrading my local gradle version to 2.12: sdk install gradle 2.12
Run the wrapper command
Restore my local version to 4.2.1: sdk install gradle 4.2.1

Gradle tasks from build.gradle are not getting listed

The gradle task that I have added to my build.gradle is not getting listed.
This is how my build.gradle looks
task helloWorld {
doLast {
println 'Hello world from gradle.'
}
}
However when I run gradle tasks the task helloWorld is not listed. Please help.
The gradle version is the following.
$ gradle -v
------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------
Build time: 2017-03-03 19:45:41 UTC
Revision: 9eb76efdd3d034dc506c719dac2955efb5ff9a93
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_31 (Oracle Corporation 25.31-b07)
OS: Mac OS X 10.11.6 x86_64
Looks like we need to use --all switch. The following works.
$ gradle tasks --all

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