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 :)
Related
I'm using Cordova and when I run cordova build android it's throwing an error. Like several months ago, it was no problem building the APK. I think Java did auto update, causing an issue?
I suppose it has something to do with the com.google.gms:google-service and maybe the gradle? I've no clue.
This is the full terminal output:
% cordova build android
[Gradle Properties] Detected Gradle property "android.useAndroidX" with the value of "true", Cordova's recommended value is "false"
[Gradle Properties] Detected Gradle property "android.enableJetifier" with the value of "true", Cordova's recommended value is "false"
cordova-plugin-firebasex: Preparing Firebase on Android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: /Users/<user>/Library/Android/sdk
Subproject Path: CordovaLib
Subproject Path: app
> Configure project :app
Adding classpath: com.google.gms:google-services:4.2.0
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
> Task :app:processDebugGoogleServices
Parsing json file: /Users/<user>/Sites/cordova/<projectname>/platforms/android/app/google-services.json
> Task :CordovaLib:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':CordovaLib:compileDebugJavaWithJavac'.
> java.lang.NullPointerException (no error message)
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
21 actionable tasks: 5 executed, 16 up-to-date
Command failed with exit code 1: /Users/<user>/Sites/cordova/<project>/platforms/android/gradlew cdvBuildDebug -b /Users/<user>/Sites/cordova/<project>/platforms/android/build.gradle
Versions
javac -version
javac 1.8.0_292
------------------------------------------------------------
Gradle 6.9.1
------------------------------------------------------------
Build time: 2021-08-20 11:15:18 UTC
Revision: f0ddb54aaae0e44f0a7209c3c0274d506ea742a0
Kotlin: 1.4.20
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.12 (Homebrew 11.0.12+0)
OS: Mac OS X 11.3.1 x86_64
Thanks for any advice in advance!
Okay.. So I solved this part, but wanted to keep this post here for others who might run into the same problem.
Gradle
brew uninstall gradle#6 (because I manually installed this version)
brew install gradle (which is installing version 7.1.1 currently)
Cordova
cordova platform remove android (I was on 9)
cordova platform add android#10.1.0
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
When working with the latest Gradle version with Java 10 on Linux, it fails to identify version number of Java as 10 as valid Java version. How to fix this problem on Linux machines ? Log details of the error here
And here is the complete error report (N.B. Running gradle --version or gradle -v also gives the same output :
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
EDIT :
Output of gradle --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10'.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
java.lang.IllegalArgumentException: Could not determine java version from '10'.
at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:70)
at org.gradle.api.JavaVersion.current(JavaVersion.java:80)
at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:32)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Output of java --version
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
You need to upgrade Gradle. Version 4.5.1 and later definitely support Java 10.
If you think you have 4.5.1 or later installed, but gradle -version still won't run, it's possible that when you type gradle at the command line, it's still running an older version for some reason.
One common thing to do is alias gradle to ./gradlew, so that in the context of a Gradle project, you'll use the wrapper Gradle rather than the system Gradle. This is usually helpful, but in a situation like this, it backfires. You should be able to determine the installed system Gradle with which:
> which gradle
/usr/local/bin/gradle
> $(which gradle) -version
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
(I've elided some warnings about illegal reflective access, if you get those, don't worry about them.)
If $(which gradle) -version still won't run, you need to upgrade the system gradle. But if it does, to update the Gradle wrapper, you can edit your build.gradle --
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
}
-- and then use the system Gradle to rerun the wrapper task:
> $(which gradle) wrapper
Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 7s
1 actionable task: 1 executed
> ./gradlew -version
Downloading https://services.gradle.org/distributions/gradle-4.6-bin.zip
......................................................................
[etc.]
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
Take help of ppa and upgrade your gradle version , Ubuntu 17 comes with gradle sudo apt install gradle will install default gradle version.
to upgrade for java 10 need to run below command.
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt upgrade gradle
Guys I Found the problem in this case. I installed gradle from the official debian repositories which contained an outdated version of gradle which didn't support Java 10. On downloading and installing Gradle from the official site and soft linking it to the /usr/bin/gradle , it worked just fine. So the problem essentially was installing gradle from the debian repositories which are currently outdated.
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'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.