flathub / com.jetbrains.IntelliJ-IDEA-Ultimate

https://flathub.org/apps/details/com.jetbrains.IntelliJ-IDEA-Ultimate
15 stars 8 forks source link

Gradle fails because of TMPDIR not properly set #110

Open maciex opened 2 years ago

maciex commented 2 years ago

clean/build/refresh of gradle project in IntelliJ fails with the error below:

The specified initialization script '/tmp/ijmapper.gradle' does not exist.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.IllegalArgumentException: The specified initialization script '/tmp/ijmapper.gradle' does not exist.

This seems related to #4

I tried setting export TMPDIR=${XDG_CACHE_HOME}/tmp and then running IntelliJ, but it still failed. The file /tmp/ijmapper.gradle reported as not existing seems to be present under that path in the flatpak env.

x80486 commented 2 years ago

I haven't seen this one anymore once TMPDIR was set. I assume you are running the tasks in the built-in Terminal from IntelliJ IDEA.

What Gradle version are you using?

maciex commented 2 years ago

I'm not running the tasks manually. The project is imported as Gradle project and IntelliJ tries to build it, but it fails.

$ ./gradlew --version

------------------------------------------------------------
Gradle 6.8.2
------------------------------------------------------------

Build time:   2021-02-05 12:53:00 UTC
Revision:     b9bd4a5c6026ac52f690eaf2829ee26563cad426

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_311 (IBM Corporation 2.9)
OS:           Linux 5.18.13-200.fc36.x86_64 amd64
maciex commented 2 years ago

Maybe this line should be changed? https://github.com/flathub/com.jetbrains.IntelliJ-IDEA-Ultimate/blob/master/entrypoint.sh#L7

to:

TMPDIR="${XDG_CACHE_HOME}/tmp"

I'm in the middle of building the flatpak to test this.

maciex commented 2 years ago

Unfortunately the above mentioned PR does not seem to work :|

When Gradle is syncing the files (Refresh All Gradle Projects) it still fails and complains about missing /tmp/ijmapper.gradle. But the file is there.

Maybe Gradle can't access the /tmp ? Or Gradle is not run in flatpak (that doesn't seem possible)?

maciex commented 2 years ago

I think I found a fix for the issue. I added the lines below to the entrypoint.sh:

GRADLE_OPTS="-Djava.io.tmpdir=${TMPDIR}"
export GRADLE_OPTS

I'm not sure if this can/should be added to the flatpak.

maciex commented 2 years ago

It worked for few minutes, the IDE synced the gradle projects properly. But then again it failed: image

maciex commented 2 years ago

I've got a clue why works at first, but then starts failing. This is most probably caused by the already running gradle daemon. If no daemon is running and I run a project refresh in the IDE it works. But if I run the gradle build outside of the IDE, then the daemon has "wrong" settings, and next refresh/build from IDE will fail.

Currently I don't know how to fix or workaround this problem.

mihalyr commented 10 months ago

This is most probably caused by the already running gradle daemon. If no daemon is running and I run a project refresh in the IDE it works.

Thank you a lot for this hint @maciex I was fighting this issue for a while today with Community edition. Now at least I have a workaround by running gradle --stop outside the flatpak and then the reload in IDEA works again.

I'm not sure if there is a good solution, I might need to go back to installing IntelliJ normally if I want to run gradle also outside the flatpak regularly.

maciex commented 9 months ago

@mihalyr Another type of workaround for this problem (instead of running gradlew --stop) could could be adding -Dorg.gradle.daemon=false to the gradle opts, both in IntelliJ and in the console, or only in one of them.

This will avoid running a gradle daemon, which is then shared between those envs, and we want to avoid it.

mihalyr commented 9 months ago

@maciex indeed! that's probably the right way to go about this. However, I dropped the flatpak for now and just installed it via toolbox, it seemed easier at the moment.

x80486 commented 9 months ago

You can still have the Gradle daemon active, but if you are using the Flatpak version, make sure to remap the temp directory.

Setting java.io.tmpdir = /run/user/1000/app/com.jetbrains.IntelliJ-IDEA-Ultimate will solve the issue. The easiest (and less intrusive) way is to source it by the GRADLE_OPTS environment variable.

image

Just remember these values won't change once the JVM is up and running.