konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.65k stars 265 forks source link

Running gradle generateJavaScript task repeatedly fails #715

Open McMurat opened 1 year ago

McMurat commented 1 year ago

Hello, first off thank you very much for developing TeaVM!

I have recently switched my TeaVM build process from maven to gradle. Everything works perfectly when I run the generateJavaScript the first time. Afterward, every repeated execution most of the time fails as some build files seem to be blocked by the previous TeaVM build process which is still running in a background process (maybe a gradle daemon?) after the build completed. To fix this, I currently need to kill all those running gradle Java processes manually before running generateJavaScript again. Do you have any ideas which could fix this? On top of that, is there some kind of "autocompile" functionality which avoids running generateJavaScript manually in the first place?

I am using the most recent TeaVM version and Windows.

Thank you very much!

konsoletyper commented 1 year ago

Hello. I don't know what's going on, can't reproduce on my side. Perhaps this is something Windows-specific. Can you provide more details on which files are blocked?

On top of that, is there some kind of "autocompile" functionality which avoids running generateJavaScript manually in the first place?

Sorry, what do you mean?

konsoletyper commented 1 year ago

On thing you can do to work-around this issue is to set outOfProcess property. In this case TeaVM will run in a separate process each time, which can slow down your build, but at least this should help you to avoid file blocking issues on Windows.

konsoletyper commented 1 year ago

BTW, I just tried to fix the issue, however I can't check if my commit helps. Could you please check out latest TeaVM sources, build them locally and check, if everything works with my latest commit?

McMurat commented 1 year ago

Thank you very much! Setting outOfProcess = true fixed the issue and had no noticable negative impact (slower build time...) for me, so I did not check your new commit, yet.

Can you provide more details on which files are blocked? I don't know which files are blocked, I just assumed something like that because TeaVM suddenly states that lots of my project's classes are missing when the bug occurs. And Java VM instances stack up in my taskmanager and after I kill them manually, it works again.

On top of that, is there some kind of "autocompile" functionality which avoids running generateJavaScript manually in the first place?

Sorry, what do you mean?

I was thinking about some feature which automatically regenerates the TeaVM generated code on changes in the IntelliJ IDE, like some kind of "build on save" functionality.

konsoletyper commented 1 year ago

I was thinking about some feature which automatically regenerates the TeaVM generated code on changes in the IntelliJ IDE, like some kind of "build on save" functionality.

Unfortunately, I don't know if it's possible with the tooling. Gradle has continuous build functionality, but I did not test it and I'm not sure it's possible to trigger it manually from IDEA (e.g. when you press "save" button). You can also look at IDEA plugin, which provides dev server, which in turn can rebuild JS file on changes in class files. However, this works kind of unreliable in case of multi-module project and still (in case of Gradle) requires to run classes task manually. The only advantage of such server is incremental build: it caches as much as possible in the memory and tries to recompile only changed parts.