I have a version history that I'm trying to run a gradle build on and in my bash script I have
while read -r version
do
git checkout $version
gradle clean
gradle javadoc
...
done < version-history.log
which is trying to get the documentation for every tagged release of my code. The problem is that gradle runs a build once and then breaks out of the for loop. I tried encapsulating it in a function call, but it still manages to break out of the loop. Is this behavior intentional? How can I prevent it from doing this? My gradle version is
------------------------------------------------------------
Gradle 6.2.1
------------------------------------------------------------
Build time: 2020-03-01 17:25:20 UTC
Revision: <unknown>
Kotlin: 1.3.61
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 13.0.2 (Oracle Corporation 13.0.2+8)
OS: Linux 5.5.6-arch1-1 amd64
Gradle consumes the input for some reason, which is what causes this behavior. Appending </dev/null to the gradle call seems to fix the problem, try
while read -r version; do
git checkout $version
gradle clean </dev/null
done <version-history.log
Related
Not a java dev touching java for the first time, can't get gradle to work.
I'm trying to install this extension for Ghidra. The readme says I should run:
GHIDRA_INSTALL_DIR=${GHIDRA_HOME} gradle
I've installed java 18 and gradle on a mac. When running the above, I get the following error:
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :copyDependencies NO-SOURCE
> Task :compileJava FAILED
/home/gradle/project/src/main/java/ghidra/app/plugin/core/analysis/eBPFSolanaAnalyzer.java:156: error: text blocks are not supported in -source 11
func.setComment("""
^
(use -source 15 or higher to enable text blocks)
1 error
FAILURE: Build failed with an exception.
Tried running out of docker too (thinking it was a problem with my installation):
docker run --rm -u gradle -e GHIDRA_INSTALL_DIR=/home/gradle/project/installed -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle
But alas get the exact same error.
Why does gradle think I have Java 11 when in fact I have java 18? gradle -v gives me:
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time: 2022-03-31 15:25:29 UTC
Revision: 540473b8118064efcc264694cbcaa4b677f61041
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 18.0.1.1 (Homebrew 18.0.1.1+0)
OS: Mac OS X 12.4 x86_64
This is probably total newb question but like I said I've never touched java:) Any help super appreciated.
The error means that the project has been configured to be compatible with Java 11, which is why you can't use features from newer versions (even if you run with a newer version).
While I don't know the Ghidra project, you can see from the build file in the extension that it applies a script from the base project:
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle"
Then, if you head over to the Ghidra project and find the extension file, you can see that it indeed configures the source and target version:
compileJava {
sourceCompatibility = ghidraProps.getProperty('application.java.compiler')
targetCompatibility = ghidraProps.getProperty('application.java.compiler')
dependsOn copyDependencies
}
These appear to come from the properties file located in Ghidra/application.properties:
application.name=Ghidra
application.version=10.2
application.release.name=DEV
application.layout.version=1
application.gradle.min=6.8
application.java.min=11
application.java.max=
application.java.compiler=11
So I would imaging that if you find this file in your local installation, you can change the application.java.compiler property to 18. Just be aware that Ghidra might not not actually support it - or it might work just fine; try it out :)
This was my output of gradle -v (in a project using the wrapper):
$ ./gradlew -v
------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
OS: Linux 3.10.0-862.11.6.el7.x86_64 amd64
See especially this line:
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
I was wishing to switch to OpenJDK 11. So select it as you can see below:
# alternatives --config java
There are 4 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/java/jdk-11.0.1/bin/java
+ 2 /usr/local/jdk-11.0.1/bin/java
3 /usr/java/jre1.8.0_191-i586/bin/java
4 /usr/java/jdk1.8.0_191-amd64/jre/bin/java
Enter to keep the current selection[+], or type selection number: 2
# java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
But there is no difference in gradle -v output. So I searched the web and find some ways (see here):
Editing gradle.properties file
Using -Dorg.gradle.java.home command line option
Editing build.gradle file
I used the first two ways. Both worked (to test I switched to JDK 8 and then run build task. The task failed due to some new features in my codes that aren't supported by Java 8). But the result of gradle -v remained unchanged still! Even using the second way:
# ./gradlew -Dorg.gradle.java.home=/usr/java/jdk1.8.0_191-amd64 -v
------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
OS: Linux 3.10.0-862.11.6.el7.x86_64 amd64
So the question is how to check which JDK version is used by Gradle during build process?
You can add a task that prints what you need when executed (Kotlin DSL):
tasks {
val j by creating {
doLast {
println(System.getProperty("java.home"))
}
}
}
Groovy DSL:
tasks.register("j") {
doLast {
println System.getProperty("java.home")
}
}
Then executing ./gradlew j:
/usr/lib/jvm/java-8-openjdk/jre
Why could gradlew use another JVM? Take a look at this script and you'll see that it uses JAVA_HOME variable to search for JVM. So probably the version from your PATH is not the same, that JAVA_HOME is pointing to.
I find an alternative way (except #madhead answer) just for when you use a Gradle daemon:
First, find PID of daemon by running gradlew --status (see here for more information). Sample output:
PID STATUS INFO
11432 IDLE 5.0
Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/5.0/userguide/gradle_daemon.html#sec:status
Then use PID to find which JDK is used:
ll /proc/<PID>/exe
Sample output:
lrwxrwxrwx. 1 0xy 0xy 0 Jan 5 04:03 /proc/11432/exe -> /usr/local/jdk-11.0.1/bin/java
On Windows:
> wmic process where "processId=<PID>" get Name, ProcessID, ExecutablePath
Sample output:
ExecutablePath Name ProcessId
C:\Program Files\Java\openjdk-11.0.1\bin\java.exe java.exe 11432
I've installed gradle on MAC using terminal.
brew install gradle
Gradle has been installed successfully.
gradle -v
------------------------------------------------------------
Gradle 3.3
------------------------------------------------------------
Build time: 2017-01-03 15:31:04 UTC
Revision: 075893a3d0798c0c1f322899b41ceca82e4e134b
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_112 (Oracle Corporation 25.112-b16)
OS: Mac OS X 10.12.3 x86_64
but I can not find gradle home.
echo $GRADLE_HOME
[empty result]
the first step to determine home directory is detect location of gradle instruction:
which gradle
/usr/local/bin/gradle
there is incomprehensible bash file.
Any ideas how to detect gradle home directory via terminal?
You can use command:
brew info gradle
As the result you will have something like this:
gradle: stable 4.0.1
Build system based on the Groovy language
https://www.gradle.org/
/usr/local/Cellar/gradle/3.4 (181 files, 74.5MB) *
Built from source on 2017-02-24 at 15:01:34
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Requirements
Required: java >= 1.7 ✔
==> Options
--with-all
Installs Javadoc, examples, and source in addition to the binaries
Here, on the line 4 you can see the home path : /usr/local/Cellar/gradle/3.4
You can retrieve the path for GRADLE_HOME automatically using the following snippet in your .bashrc or .zshrc:
export GRADLE_HOME=$(brew info gradle | grep /usr/local/Cellar/gradle | awk '{print $1}')
This is handy when the path to Gradle's home changes, when Gradle is updated.
On Mojave (v10.14), Gradle v5.4, I had to append libexec after Gradle version for IntelliJ to work.
/usr/local/Cellar/gradle/5.4/libexec
I've gradle installed When using homebrew, below one failed with me, and kept telling undefined:
/usr/local/Cellar/gradle/<version>
The below symlink worked perfectly, and solved my issue:
/usr/local/opt/gradle/libexec
"brew info gradle" command not always give the installed path
br*ew info gradle
gradle: stable 5.6.3
Open-source build automation tool based on the Groovy and Kotlin DSL
https://www.gradle.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Requirements
Required: java >= 1.8 ✔
==> Analytics
install: 29,106 (30 days), 144,607 (90 days), 611,211 (365 days)
install_on_request: 28,237 (30 days), 137,584 (90 days), 577,691 (365 days)
build_error: 0 (30 days)*
On Mojave, Gradle v6.6, I appended libexec after Gradle version for IntelliJ to work.
/usr/local/Cellar/gradle/5.4/libexec
My point isn't enough for commenting on flic's answer in the previous post.
If it happens to be in MacOS, the asterisk should be escaped as:
brew info gradle | sed -nE 's#^(/usr/local/Cellar/gradle/[^ ]+).+\*#\1#p'
or there will be sed: 1: "s#^(/usr/local/Cellar/g ...: RE error: repetition-operator operand invalid" error reported.
I have instaled Gradle, JVM and Ubuntu.
$ gradle -v
------------------------------------------------------------
Gradle 3.5
------------------------------------------------------------
Build time: 2017-04-10 13:37:25 UTC
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 9-ea (Oracle Corporation 9-ea+162)
OS: Linux 4.10.0-21-generic amd64
And I have java project on intellij.
My Gradle config:
apply plugin:'java'
When I run gradle build:
$ gradle build
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
In what there can be an error?
It helped me:
export JDK_JAVA_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED'
Just execute in the terminal.
I'm just starting out with Gradle and am almost certainly missing something obvious. My system has Java 7 installed as the default but I want all my Gradle projects to be using Java 8 by default. So, I create a ~/gradle.properties file and put the following in it:
$ cat ~/gradle.properties
org.gradle.java.home = /usr/lib/jvm/java-8-openjdk-amd64
But that doesn't appear to be honored. First, if I try to build my project I get:
Execution failed for task ':compileJava'.
> invalid source release: 1.8
Also, gradle --version gives:
$ gradle --version
------------------------------------------------------------
Gradle 1.5
------------------------------------------------------------
Gradle build time: Wednesday, October 8, 2014 8:21:39 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.4 compiled on October 7 2014
Ivy: non official version
JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
OS: Linux 3.16.0-4-amd64 amd64
However, if I copy ~/gradle.properties to my project directory (the directory with the build.gradle file) or if I run JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 gradle assemble it works. So there's not a syntax error or anything in my gradle.properties file and the JDK path is correct. For some reason the properties file is ignored if it's in my home dir.
Note that I don't have a gradle.properties in my project directory and I also tried putting the file in ~/.gradle/gradle.properties. I also did a bunch of Google and StackOverflow search and just can't find an answer to this seemingly obvious question.
Long story short, gradle reads gradle.properties from ~/.gradle/gradle.properties not ~/gradle-properties and the docs are pretty clear about that. In short, I'm a knuckle-head.