1 year ago
#384568
Hervé Guillemet
Gradle tasks loading a JNI library cannot work in daemon mode
I have developed a custom Gradle task that needs to load a JNI library (System.load
), from a custom class loader.
That's not a problem if Gradle is run with --no-daemon
command line option, but if the task is run in the daemon, the library stays loaded until the daemon feels like garbage collecting my class loader. The consequences are:
- if I run the task again, an
UnsatisfiedLinkError
exception is thrown since a native library can be loaded by only one class loader. - on Windows, any removal of the library will fail because it is loaded and locked.
I have tried to execute the loading part of the task in a process-isolated worker so that the library is unloaded when the process ends, but workers also stay around, idle, until a similar work is submitted with the same parameters and the process never ends. I didn't find a way to prevent a worker from being reusable and make it exit after the work.
Any idea how to run a library-loading task in Gradle daemon ?
java
gradle
java-native-interface
0 Answers
Your Answer