Gradle ignores daemon ignore flag - java

I'm running Gradle 3.2.1 on MacOS X 10.12.1 installed with brew install gradle, did not set any env variables etc. myself, trying to use the Java 9 EA:
gradle build -Dorg.gradle.java.home=~/jdk-9.jdk/Contents/Home
But the build is failing with
FAILURE: Build failed with an exception.
What went wrong: Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example,
an unrecognized jvm option is used.
From what I know it fails because the daemon is trying to use the maxpermsize JVM option (which is not supported in Java 8+ but in Java 8 it's only a warning).
So I tried to disable the daemon:
mkdir -p ~/.gradle && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties
But gradle build is still trying to start a daemon... I removed ~/.gradle and .gradle in the project directory. Any other ideas?
$ gradle build -Dorg.gradle.daemon=false -Dorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.2.1/userguide/gradle_daemon.html.
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/3.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
> Starting Daemon%

Ok so I figured it out, since I'm running my build like this:
gradle build -Dorg.gradle.java.home=~/jdk-9.jdk/Contents/Home
Gradle has to spawn a new thread to use a different Java version than the one pointed to by JAVA_HOME. This is done by spawning a daemon thread (even despite the false option) with that Java version and is failing. The same would happen if I passed JVM args to the build apparently.
The solution is to instead set JAVA_HOME in the terminal export JAVA_HOME=~/jdk-9.jdk/Contents/Home and just run gradle build.
Still doesn't work because the newest Java9 build broke Gradle's reflection but that's a different story.

I am posting this here since it's too big of a comment (but it is for sure not an answer).
If you run your script with --debug you will see the underlying error. I am running this directly via java-9 without setting the JAVA_HOME btw.
I had the same issue a few jdk-9 builds back and tackled it with:
set _JAVA_OPTIONS "-Dsun.reflect.debugModuleAccessChecks=true
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent=ALL-UNNAMED
--add-opens=java.base/java.text=ALL-UNNAMED"
set instead of export because I'm using fish, but should work for bash the same way.
Interestingly enough this still fails with build 153 with this:
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module #67080771
But that is specified within _JAVA_OPTIONS. This might be a regression on build 153.

Related

Unrecognized VM option 'MaxPermSize=512m' and Could not create the Java Virtual Machine when running React Native Apps (closed)

I tried to run react native app with this command.
npx react-native run-android --variant=stagingDebug --appId com.xx_staging
But I am getting this error message. I want to run multiple java versions on my machine. How can I do that? Also I don't want to change the MaxPermSize=512m. I want to keep MaxPermSize=512m as it is.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 2228 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
'"adb"' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.7/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-18.0.2.1\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\rbza9\.gradle\wrapper\dists\gradle-6.7-all\cuy9mc7upwgwgeb72wkcrupxe\gradle-6.7\lib\gradle-launcher-6.7.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* 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
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installStagingDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.7/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-18.0.2.1\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\rbza9\.gradle\wrapper\dists\gradle-6.7-all\cuy9mc7upwgwgeb72wkcrupxe\gradle-6.7\lib\gradle-launcher-6.7.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* 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
at makeError (F:\test\xx\node_modules\execa\index.js:174:9)
at F:\test\xx\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (F:\test\xx\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (F:\test\xx\node_modules\#react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
How can I fix this error?
This option was completely removed between Java 11 and Java 17. If you want to use Java 17 or later you must remove MaxPermSize=512m - the JVM will plainly refuse to start if that option is present .
Please note that already with Java 8 this option no longer had any effect and can therefore be safely removed even for Java 8. (https://docs.oracle.com/javase/9/migrate/)
The only possible reason to keep this option in some configurations is if you still must support Java 7. But Java 7 is so much outdated that IMHO it is questionable if any time spent supporting Java 7 is time well spent.
The option seems to be decommissioned.
You can add to the command line which starts your app a flag -XX:+IgnoreUnrecognizedVMOptions. In this case, JVM will ignore all unrecognized flags.

How can I solve Build Failed problem with React Native?

I am new to React Native and I recently build a simple application and I want to release it but I get the following error (I had followed every step mentioned in the blog by react native)
The Problem I encountered while running gradlew assembleRelease is FAILURE: Build failed with an exception
Output
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.9/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-18\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\Lucifer\.gradle\wrapper\dists\gradle-6.9-all\dooywd8nv05k16orzxge2b1bs\gradle-6.9\lib\gradle-launcher-6.9.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.9
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* 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
I don't know if it is the problem with JDK
I have properly installed JDK (Version 18) and added the path to SDK in the environment variable
ANDROID_HOME = C:\Users\Username\AppData\Local\Android\Sdk
and I also have added the path to java/jdk-18/bin folder and platform-tools in environment paths variable
I tried some of the solutions from previous issues regarding this problem like this one but none of them worked.
I tried reading documentation and GitHub issues but couldn't find relevant solution
so
How exactly do I solve this problem?

I can not run anything with gradle [duplicate]

This question already has answers here:
Unable to locate tools.jar
(35 answers)
Closed 2 years ago.
So, I have this problem, and it is that every time I try to run Gradle from Eclipse it gives me this error:
Working Directory: C:\Users\Owen\eclipse-workspace\SimpleMultiplycationProgram\SimpleMultiplycationProgramApp
Gradle user home: C:\Users\Owen\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 4.3.1
Java Home: C:\Program Files\Java\jre1.8.0_251
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run
:SimpleMultiplycationProgramApp:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':SimpleMultiplycationProgramApp:compileJava'.
> Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_251 contains a valid JDK installation.
* 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 13s
1 actionable task: 1 executed
So, I started trying to fix this but all the stackoverflow questions and tutorials say to do something like running ./gradle biuld it gives me this error (from cmd):
'.' is not recognized as an internal or external command,
operable program or batch file.
`/gradle biuld' gives me:
'/gradle' is not recognized as an internal or external command,
operable program or batch file.
and gradle biuld gives me:
'gradle' is not recognized as an internal or external command,
operable program or batch file.
and C:\Users\Owen.gradle is a folder, so what is going on?
This seems to be about two unrelated problems. For one, you don't seem to have gradle on your PATH, hence why the command is not recognized. And then you're also missing rt.tools. See if this other question helps you solve it. You seem to have downloaded only the JRE and not the JDK.
It appears to me that you are using a JRE instead of JDK. Possible that you pointed $JAVA_HOME environment variable to a JRE when it was meant to be JDK.
To use gradle, if you have a wrapper in your project directory named "gradlew", call it like this: ./gradlew ...
But if you don't have it, you should run the "wrapper" task to generate them.
You can also install gradle instead. But keep in mind it doesn't help with your issue. Take a look at this article for installing gradle.

Stacktrace option for Gradle task in Eclipse

A Gradle task classesPipeline is being run in Eclipse. This task assembles .class files by depending on the standard classes task, then attempts executing a batchfile.
All goes fine until the batchfile, where the script dies a horrible death in Eclipse, by printing to console:
Execution failed for task ':classesPipeline'.
> A problem occurred starting process 'command '../SomeFolder/SomeBatchfile.bat''
* 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.
The log suggests to run the task with --stacktrace, but how do I do this?
So I checked the project settings, the Gradle section offers no command line arguments, as far as i see. It is noteworthy, that running the task with --stacktrace via gradlew is of no value to me, because the task executes just fine in this case, this is only happening in Eclipse specifically.
TL;DR:
How can a gradle task be executed from Eclipse, while passing arguments to it?
To anyone who may come into contact with this problem:
I found the solution in a different, but closely related question:
How can I make "gradle --stacktrace" the default?
It is sufficient to add the following to the build.gradle:
gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.ShowStacktrace.ALWAYS

Gradle project sync failed in android studio in linux

I use android studio in linux os. When I create a project or open a new project, I found the following error:
Error:Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at http://gradle.org/docs/2.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
22:25:20.715 [main] DEBUG o.g.l.daemon.bootstrap.DaemonMain - Assuming the daemon was started with following jvm opts: [-XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx512M, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant]
FAILURE: Build failed with an exception.
What went wrong:
Could not create service of type DaemonContext using DaemonServices.createDaemonContext().
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
how to resolve this problem in linux os on my android studio?
I had this problem in Ubuntu 14.04 where /tmp was mounted with noexec parameter. To fix this I needed to remount with exec allowed:
mount -o remount,exec /tmp
The issue is referenced here:
https://discuss.gradle.org/t/gradle-v1-12-daemon-fails-to-start-if-tmp-is-mounted-with-noexec/2077

Categories