1

I have found information on how to run the GraalVM native image tracing agent from a Spring Native Maven project, but I can't find info on how to do it from a Gradle project.

See https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#_using_it_with_maven.

Any ideas on how to do it from a Gradle project?

Magnus Larsson
  • 562
  • 5
  • 10

1 Answers1

5

The assisted configuration javaagent is orthogonal to the build tool, so one needs to specify the correct arguments to the jvm running the tests:

Something like this which the docs you reference outline: -agentlib:native-image-agent=access-filter-file=access-filter.json,config-output-dir=target/classes/META-INF/native-image

I think in Gradle you just configure the test task with it:

test { 
  jvmArgs -agentlib:native-image-agent=access-filter-file=access-filter.json,config-output-dir=target/classes/META-INF/native-image
}

Here's Gradle docs on the test task: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

Oleg Šelajev
  • 3,530
  • 1
  • 17
  • 25
  • Thanks for the info. I tried with: test { useJUnitPlatform() jvmArgs '-agentlib:native-image-agent=access-filter-file=src/test/resources/access-filter.json,config-output-dir=ml' } I hoped to get some output in the folder "ml", but it was empty after running: ./gradlew clean bootBuildImage – Magnus Larsson Apr 20 '21 at 13:37
  • I think it adds the jvmArgs for the test runs. Is it still empty after `./gradlew test`? – Oleg Šelajev Apr 20 '21 at 14:16
  • Yes it does! Given that GraalVM is installed and added to $PATH :-) Running ./gradlew test works for me, I guess. I can thenmove the files after inspection to src/resources/META-INF/native-image and run a separate ./gradlew bootBuildImage command. I'll try it out! – Magnus Larsson Apr 21 '21 at 17:34
  • Just to confirm this works perfectly fine. My native compiled Spring Boot apps runs perfectly fina now. Amazing to see them start up in 150 ms :-) – Magnus Larsson Apr 22 '21 at 09:52