native-build-tools icon indicating copy to clipboard operation
native-build-tools copied to clipboard

Compatibility issue with Gradle's configuration cache in `CollectReachabilityMetadata` task

Open CXwudi opened this issue 2 years ago • 10 comments

Before reporting

  • [x] This repository should be used to report issues on the Maven or Gradle plugins for GraalVM.
  • [x] Please report issues which are specific to the Spring Framework or the Micronaut framework to their specific repositories.
  • [x] Do not report issues with building your specific application, e.g errors which happen at image build time like classes initialized at build time, or missing classes as run time: those are not related to the plugins but problems with configuration. You can refer to the GraalVM native image documentation for available options and the plugins documentation for how to use them with the plugin.

Describe the bug The task collectReachabilityMetadata fails with Gradle's configuration cache enabled

To Reproduce Use Gradle 8.1, create a new application type Java project using gradle init, enable configuration cache, and add the native gradle plugin in the build.gradle.kts

Or use this minimal reproducible sample, test.zip

Run ./gradlew app:collectReachabilityMetadata

Expected behavior

The Gradle command should run successfully

Logs

```
🚀 ./gradlew app:collectReachabilityMetadata
Encryption of the configuration cache is enabled.
Calculating task graph as no configuration cache is available for tasks: app:collectReachabilityMetadata

FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache problems found in this build.

25 problems were found storing the configuration cache, 5 of which seem unique.
- Plugin class 'org.gradle.api.plugins.JavaBasePlugin': execution of task ':app:collectReachabilityMetadata' caused invocation of 'Task.project' in other task at execution time which is unsupported.
  See https://docs.gradle.org/8.1/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:app:collectReachabilityMetadata` of type `org.graalvm.buildtools.gradle.tasks.CollectReachabilityMetadata`: cannot serialize object of type 'org.gradle.api.artifacts.Configuration' as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.1/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:app:collectReachabilityMetadata` of type `org.graalvm.buildtools.gradle.tasks.CollectReachabilityMetadata`: execution of task ':app:collectReachabilityMetadata' caused invocation of 'Task.convention' in other task at execution time which is unsupported.
  See https://docs.gradle.org/8.1/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:app:collectReachabilityMetadata` of type `org.graalvm.buildtools.gradle.tasks.CollectReachabilityMetadata`: execution of task ':app:collectReachabilityMetadata' caused invocation of 'Task.project' in other task at execution time which is unsupported.
  See https://docs.gradle.org/8.1/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:app:collectReachabilityMetadata` of type `org.graalvm.buildtools.gradle.tasks.CollectReachabilityMetadata`: invocation of 'Task.project' at execution time is unsupported.
  See https://docs.gradle.org/8.1/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution

See the complete report at file:///D:/coding-workspace/jvm-project/experiment/test/build/reports/configuration-cache/f08dxrrrchazgw6h5vryx7ytw/70mwsvs3jo0tz5pug7tk4107v/configuration-cache-report.html
> Invocation of 'Task.project' by task ':app:collectReachabilityMetadata' at execution time is unsupported.
> Execution of task ':app:collectReachabilityMetadata' caused invocation of 'Task.project' by task ':app:compileJava' at execution time which is unsupported.
> Execution of task ':app:collectReachabilityMetadata' caused invocation of 'Task.convention' by task ':app:compileJava' at execution time which is unsupported.
> Execution of task ':app:collectReachabilityMetadata' caused invocation of 'Task.project' by task ':app:compileJava' at execution time which is unsupported.

* 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 3s
1 actionable task: 1 executed
```

Also, the configuration-cache-report.html file -> configuration-cache-report.zip

System Info:

  • OS: Windows 10 Pro 22h2
  • GraalVM Version: 22.3 CE
  • Java Version: 17
  • Plugin version: native-gradle-plugin:0.9.21

Additional context This issue is similar but not too similar to #338, this compatibility issue comes from the CollectReachabilityMetadata task. This task is used by the bootJar task from the Spring Gradle plugin. So it actually breaks Spring plugin when configuration cache is enabled.

./gradlew build and ./gradlew nativeBuild are not affected, if we don't let them dependsOn the collectReachabilityMetadata task.

CXwudi avatar Apr 20 '23 03:04 CXwudi

I have the same issue, do you have any workaround except disabling configuration cache entirely?

morki avatar Jul 18 '23 18:07 morki

@morki neither did I know

CXwudi avatar Jul 19 '23 00:07 CXwudi

we use these flags to get around those warnings (YMMV):

org.gradle.configuration-cache = true
org.gradle.configuration-cache.problems = warn
org.gradle.configuration-cache.stable = true

and, if necessary, in settings.gradle.kts:

enableFeaturePreview("STABLE_CONFIGURATION_CACHE")

sgammon avatar Aug 01 '23 23:08 sgammon

cc/ @morki @CXwudi

sgammon avatar Aug 01 '23 23:08 sgammon

@sgammon Based on the documentation:

The configuration cache is automatically invalidated when inputs to the configuration phase change. However, certain inputs are not tracked yet, so you may have to manually invalidate the configuration cache when untracked inputs to the configuration phase change. This can happen if you ignored problems.

I wouldn't say org.gradle.configuration-cache.problems = warn is a long term solution

CXwudi avatar Aug 02 '23 01:08 CXwudi

@CXwudi certainly not, but my configuration cache is working so i figured i'd help with a WA. i was here to report my own configuration cache issue so even these flags don't completely solve it.

sgammon avatar Aug 02 '23 19:08 sgammon

Should this issue be merged into the more general https://github.com/graalvm/native-build-tools/issues/477?

sschuberth avatar Mar 14 '25 09:03 sschuberth

Probably. I'm not even sure this one is relevant anymore. We have tests with the configuration cache and none is failing :/

melix avatar Mar 14 '25 09:03 melix

Still failing on latest @melix; could I provide a stacktrace? What's helpful?

sgammon avatar Mar 14 '25 11:03 sgammon

Ideally a test case which fails, but a stacktrace would already be helpful, thanks.

melix avatar Mar 14 '25 11:03 melix