IntelliJ is adding a no longer supported -Djava.endorsed.dirs (JDK 9+) parameter on Gradle runs which results in failure
I am attempting to run a Gradle task on a Kotlin project via Run -> Run "configuration". It worked with JDK 8, but after upgrading to JDK 9+ it fails to run.
It seems that IntelliJ is silently adding a no longer supported parameter (-Djava.endorsed.dirs) and the java process terminates because of it.
There is already code related to the issue in IntelliJ's repo: https://github.com/JetBrains/intellij-community/blob/7f14bdea49bd686a1e68c22434dd715da41dc42c/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java#L1113
But apparently the issue still happens when running a Gradle task.
The full output of run:
> Task :kaptKotlin UP-TO-DATE
> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :findMainClass
> Task :bootRun FAILED
-Djava.endorsed.dirs=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1\jre64\lib\endorsed is not supported. Endorsed standards and standalone APIs
Error: Could not create the Java Virtual Machine.
in modular form will be supported via the concept of upgradeable modules.
Error: A fatal exception has occurred. Program will exit.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk-10.0.1\bin\java.exe'' finished with non-zero exit value 1
* 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 2s
6 actionable tasks: 2 executed, 4 up-to-date
Process 'command 'C:\Program Files\Java\jdk-10.0.1\bin\java.exe'' finished with non-zero exit value 1
2:06:33: Task execution finished 'bootRun'.
Are there any workarounds for this issue?
IDE: IntelliJ 2018.1.4 (Community Edition)
OS: Windows 10 (though the same happens on linux)
Please sign in to leave a comment.
Works fine for me. Does it work from command line? Please check Gradle JVM options in Settings | Build, Execution, Deployment | Build Tools | Gradle - do you have anything configured there or in Run/Debug Configuration?
I have managed to reduce it to a small reproducible IntelliJ / Gradle project - https://app.box.com/s/41q4mwbkrls2fy5713vb6yotgzvtmyym
It did work from the command line ("gradlew.bat bootRun")
Now that I looked at it - it seems the issue is that I have the following Gradle task:
bootRun {systemProperties += System.properties
}
it adds all the System properties to the "bootRun" task (which the reduced case is configured with). For some reason the system properties contain "java.endorsed.dirs:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.4\jre64\lib\endorsed".
I checked the places you suggested and others - it is not being set anywhere. This environment variable is not set in the OS either.
So it is probably not an usual case and can be worked around by adding
systemProperties.remove("java.endorsed.dirs")to the "bootRun" task.
Is this working as intended then?
Thank you for these details! Reproduced the issue. Please follow the https://youtrack.jetbrains.com/issue/IDEA-193219
Hi
Just as a followup, I would strongly discourage using
in your bootRun task. We just spent a long time debugging why tomcat threw an exception during startup and finally found https://github.com/spring-projects/spring-boot/issues/7223 that also mentions that copying system properties from one jvm to another is probably not a good idea.
Instead you should figure out which properties you need and add them one by one.
Best regards Jens
Check the java version in the PATH system variable