Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create .json configuration files following the documentation of Gradle plugin #259

Open
jvmusin opened this issue Jun 28, 2022 · 10 comments
Labels
bug Something isn't working gradle-plugin Related to Gradle plugin
Milestone

Comments

@jvmusin
Copy link

jvmusin commented Jun 28, 2022

Describe the bug
When I ./gradlew -Pagent run an application, do some operations with it and close it not gracefully (imagine an application like while (true) { ... } and killing it), the agent creates .json files not in build/native/agent-output/run, but in build/native/agent-output/session-4671-20220628T174143Z (of smth like that). Because of that, the following task ./gradlew metadataCopy --task run --dir src/main/resources/META-INF/native-image fails saying java.io.FileNotFoundException: /path-to-the-project/build/native/agent-output/run/reflect-config.json (No such file or directory).

To Reproduce

  1. Take any project with a plugin id("org.graalvm.buildtools.native") version "0.9.12" and graalvm-ce-java11-22.1.0.
  2. Use main function like fun main() { while(true) {} }
  3. Run ./gradlew -Pagent run to produce configs
  4. Run ./gradlew metadataCopy --task run --dir src/main/resources/META-INF/native-image to copy configs to resources (you'll see an exception here)

Expected behavior
Config files are created and copied to resources folder.

Logs

Rustam.Musin@UNIT-2257 native-image-test % ./gradlew -Pagent run
[native-image-plugin] Instrumenting task with the native-image-agent: run
[native-image-plugin] Instrumenting task with the native-image-agent: test

> Task :compileKotlin
w: /Users/Rustam.Musin/my/native-image-test/src/main/kotlin/Main.kt: (1, 10): Parameter 'args' is never used
w: /Users/Rustam.Musin/my/native-image-test/src/main/kotlin/Main.kt: (3, 5): Unreachable code
w: /Users/Rustam.Musin/my/native-image-test/src/main/kotlin/Main.kt: (7, 5): Unreachable code
<==========---> 80% EXECUTING [3s]
> :run
^C%                                                                                                                                                                                                                     Rustam.Musin@UNIT-2257 native-image-test % ./gradlew -Pagent run                                                           
[native-image-plugin] Instrumenting task with the native-image-agent: run
[native-image-plugin] Instrumenting task with the native-image-agent: test
<==========---> 80% EXECUTING [5s]
> :run
^C%                                                                                                                                                                                                                     Rustam.Musin@UNIT-2257 native-image-test % ./gradlew metadataCopy --task run --dir src/main/resources/META-INF/native-image

> Task :metadataCopy FAILED
[native-image-plugin] Toolchain detection is disabled, will use GraalVM from /Users/Rustam.Musin/Library/Java/JavaVirtualMachines/graalvm-ce-java11-22.1.0/Contents/Home.
java.io.FileNotFoundException: /Users/Rustam.Musin/my/native-image-test/build/native/agent-output/run/reflect-config.json (No such file or directory)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
        at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
        at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:184)
        at java.base/java.net.URL.openStream(URL.java:1165)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.configure.ConfigurationParser.openStream(ConfigurationParser.java:55)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.configure.ConfigurationParser.openReader(ConfigurationParser.java:76)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.configure.ConfigurationParser.parseAndRegister(ConfigurationParser.java:70)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadConfig(ConfigurationFileCollection.java:164)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadTypeConfig(ConfigurationFileCollection.java:157)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadReflectConfig(ConfigurationFileCollection.java:120)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadConfigurationSet(ConfigurationFileCollection.java:150)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.ConfigurationTool.generate(ConfigurationTool.java:288)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.ConfigurationTool.main(ConfigurationTool.java:100)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':metadataCopy'.
> Process 'command '/Users/Rustam.Musin/Library/Java/JavaVirtualMachines/graalvm-ce-java11-22.1.0/Contents/Home/bin/native-image-configure'' 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 1s
1 actionable task: 1 executed
Rustam.Musin@UNIT-2257 native-image-test % 

System Info (please complete the following information):

  • OS: macOS Monterey
  • GraalVM Version: 22.1 CE
  • Java Version: 11
  • Plugin version: native-gradle-plugin:0.9.12
@jvmusin jvmusin added the bug Something isn't working label Jun 28, 2022
@jvmusin
Copy link
Author

jvmusin commented Jun 28, 2022

native-image-test.zip
Here is a sample project in case you need it.

@jvmusin
Copy link
Author

jvmusin commented Jun 28, 2022

@jvmusin
Copy link
Author

jvmusin commented Jun 28, 2022

Btw after reverse engineering a bit, I found a WA: you can replace --task run with --task run/session-4671-20220628T174143Z

@lazar-mitrovic lazar-mitrovic added the gradle-plugin Related to Gradle plugin label Jun 29, 2022
@lazar-mitrovic
Copy link
Collaborator

That session folder is used in order to make sure that concurrent agent runs don't overwrite each-others outputs -- it should at a later stage be merged using a dedicated task, however SIGKILL prevents that task from ever executing.

What it looks to me is that we need to implement a watchdog that would finalize agent processing.
WDYT @melix?

@lazar-mitrovic lazar-mitrovic added this to the 0.9.13 milestone Jun 29, 2022
@melix
Copy link
Collaborator

melix commented Jun 29, 2022

I'm not sure that would be easy to do. Hitting CTRL+C will interrupt the Gradle build and it is expected, from my POV, that it doesn't do more. Maybe we should document this behavior instead, and recommend to have a stop endpoint in the application to shutdown it cleanly (e.g [https://docs.micronaut.io/latest/guide/#stopEndpoint](what Micronaut offers).

@jvmusin
Copy link
Author

jvmusin commented Jun 29, 2022

This also happens when an application ends with an exit code != 0 or with an exception.

@melix
Copy link
Collaborator

melix commented Jun 29, 2022

If the app ends with an different exit code, you can still use --continue to get past.

@jvmusin
Copy link
Author

jvmusin commented Jun 29, 2022

Even when I use ./gradlew -Pagent run --continue, it creates config files in run/session-... subdirectory and not in just run.

@jvmusin
Copy link
Author

jvmusin commented Jun 29, 2022

Can you please mark NativeImageOptions.getAgent() and DeprecatedAgentOptions class and its methods as deprecated?

@melix melix modified the milestones: 0.9.13, 0.9.14 Jul 12, 2022
@melix melix modified the milestones: 0.9.14, 0.9.15 Sep 19, 2022
@melix melix modified the milestones: 0.9.15, 0.9.16 Oct 17, 2022
@sdeleuze sdeleuze modified the milestones: 0.9.16, 0.9.17 Oct 17, 2022
@sdeleuze sdeleuze modified the milestones: 0.9.17, 0.9.18 Oct 28, 2022
@sdeleuze sdeleuze modified the milestones: 0.9.18, 0.9.19 Nov 14, 2022
@dnestoro dnestoro modified the milestones: 0.9.19, 0.9.20 Dec 2, 2022
@sdeleuze sdeleuze modified the milestones: 0.9.20, 0.9.21 Jan 31, 2023
@dnestoro dnestoro modified the milestones: 0.9.21, 0.9.22 Apr 13, 2023
@dnestoro dnestoro modified the milestones: 0.9.22, 0.9.23 May 11, 2023
@dnestoro dnestoro modified the milestones: 0.9.23, 0.9.24 Jun 16, 2023
@dnestoro dnestoro modified the milestones: 0.9.24, 0.9.25 Aug 9, 2023
@XhstormR
Copy link

I had the same problem.

root@e3022b4218a7:/app# gradle metadataCopy --task run --dir src/main/resources/META-INF/native-image

> Configure project :
Kotlin DSL property assignment is an incubating feature.

> Task :metadataCopy FAILED
java.io.FileNotFoundException: /app/build/native/agent-output/run/reflect-config.json (No such file or directory)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:111)
        at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
        at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:189)
        at java.base/java.net.URL.openStream(URL.java:1161)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.configure.ConfigurationParser.openStream(ConfigurationParser.java:56)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.configure.ConfigurationParser.openReader(ConfigurationParser.java:77)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.configure.ConfigurationParser.parseAndRegister(ConfigurationParser.java:71)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadConfig(ConfigurationFileCollection.java:164)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadTypeConfig(ConfigurationFileCollection.java:157)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadReflectConfig(ConfigurationFileCollection.java:120)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.config.ConfigurationFileCollection.loadConfigurationSet(ConfigurationFileCollection.java:150)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.command.ConfigurationGenerateCommand.generate(ConfigurationGenerateCommand.java:273)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.command.ConfigurationGenerateCommand.apply(ConfigurationGenerateCommand.java:60)
        at org.graalvm.nativeimage.configure/com.oracle.svm.configure.ConfigurationTool.main(ConfigurationTool.java:84)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':metadataCopy'.
> Process 'command '/opt/java/graalvm/bin/native-image-configure'' finished with non-zero exit value 1

BUILD FAILED in 1s
1 actionable task: 1 executed
root@e3022b4218a7:/app# ll /app/build/native/agent-output/run/
total 0
drwxr-xr-x 3 root root  96 Aug 27 12:53 ./
drwxr-xr-x 3 root root  96 Aug 27 12:53 ../
drwxr-xr-x 9 root root 288 Aug 27 12:53 session-6549-20230827T125328Z/
root@e3022b4218a7:/app# ll /app/build/native/agent-output/run/session-6549-20230827T125328Z/
total 28
drwxr-xr-x 9 root root  288 Aug 27 12:53 ./
drwxr-xr-x 3 root root   96 Aug 27 12:53 ../
drwxr-xr-x 2 root root   64 Aug 27 12:53 agent-extracted-predefined-classes/
-rw-r--r-- 1 root root  113 Aug 27 12:53 jni-config.json
-rw-r--r-- 1 root root   65 Aug 27 12:53 predefined-classes-config.json
-rw-r--r-- 1 root root    4 Aug 27 12:53 proxy-config.json
-rw-r--r-- 1 root root 6865 Aug 27 12:53 reflect-config.json
-rw-r--r-- 1 root root 1013 Aug 27 12:53 resource-config.json
-rw-r--r-- 1 root root   71 Aug 27 12:53 serialization-config.json
root@e3022b4218a7:/app#

Replace run with run/session-6549-20230827T125328Z to successfully execute the task:

root@e3022b4218a7:/app# gradle metadataCopy --task run/session-6549-20230827T125328Z --dir src/main/resources/META-INF/native-image

> Configure project :
Kotlin DSL property assignment is an incubating feature.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
root@e3022b4218a7:/app#

@dnestoro dnestoro modified the milestones: 0.9.25, 0.9.26 Aug 28, 2023
@olpaw olpaw modified the milestones: 0.9.26, 0.9.27 Sep 7, 2023
@olpaw olpaw modified the milestones: 0.9.27, 0.9.28 Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gradle-plugin Related to Gradle plugin
Projects
None yet
Development

No branches or pull requests

7 participants