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

Regression with Gradle's configuration cache in 0.9.15 #338

Closed
wilkinsona opened this issue Oct 17, 2022 · 10 comments · Fixed by #339
Closed

Regression with Gradle's configuration cache in 0.9.15 #338

wilkinsona opened this issue Oct 17, 2022 · 10 comments · Fixed by #339
Labels
bug Something isn't working

Comments

@wilkinsona
Copy link

Describe the bug
In some circumstances, a Gradle build fails when run using --configuration-cache due to a Configuration instance that's captured by a lambda in NativeImpagePlugin. The same build works with 0.9.14.

To Reproduce
Sorry, I've yet to manage to boil things down into a minimal reproducer. Hopefully the configuration cache problem report (see below) will be sufficient to diagnose the problem.

Expected behavior
The Gradle plugin should work with --configuration-cache.

Logs

⌄ cannot serialize object of type org.gradle.api.internal.artifacts.configurations.DefaultConfiguration, a subtype of org.gradle.api.artifacts.Configuration, as these are not supported with the configuration cache. ?
  ⌄ fieldarg$1 of org.graalvm.buildtools.gradle.NativeImagePlugin$$Lambda$1852/0x0000000801a9f000
    ⌄ bean of type org.graalvm.buildtools.gradle.NativeImagePlugin$$Lambda$1852/0x0000000801a9f000
      ⌄ fieldtransformer of org.gradle.api.internal.provider.TransformBackedProvider
        ⌄ bean of type org.gradle.api.internal.provider.TransformBackedProvider
          ⌄ fieldprovider of org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec
            ⌄ bean of type org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec
              ⌄ field__configurationFileDirectories__ of org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions
                ⌄ bean of type org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions
                  ⌄ field_gr_owner_ of org.graalvm.buildtools.gradle.dsl.NativeResourcesOptions
                    ⌄ bean of type org.graalvm.buildtools.gradle.dsl.NativeResourcesOptions
                      ⌄ field__options__ of org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile
                        task:generateResourcesConfigFile of type org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile

System Info (please complete the following information):

  • OS: macOS
  • GraalVM Version: 22.2
  • Java Version: 17
  • Plugin version: 0.9.15
@wilkinsona wilkinsona added the bug Something isn't working label Oct 17, 2022
@sdeleuze sdeleuze added this to the 0.9.16 milestone Oct 17, 2022
melix added a commit that referenced this issue Oct 17, 2022
This is an attempt to fix #338
@melix
Copy link
Collaborator

melix commented Oct 17, 2022

@wilkinsona would it be possible for you to try to build and test this branch?

wilkinsona added a commit to spring-projects/spring-boot that referenced this issue Oct 17, 2022
@wilkinsona
Copy link
Author

That was quick. Thank you, @melix. That's better as the configuration cache no longer reports a problem. Unfortunately, the build still fails:

./gradlew --configuration-cache generateResourcesConfigFile
Configuration cache is an incubating feature.
Calculating task graph as no configuration cache is available for tasks: generateResourcesConfigFile

0 problems were found storing the configuration cache.

See the complete report at file:///Users/awilkinson/dev/temp/nbt-configuration-cache-problem/build/reports/configuration-cache/bub752nr41ig1gyl5xvezwkms/cku5jhqpzmyxpzegunrchhv9/configuration-cache-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache state could not be cached: field '__options__' from type 'org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile': error writing value of type 'org.gradle.api.internal.provider.DefaultProperty'
> Configuration cache state could not be cached: field '_gr_owner_' from type 'org.graalvm.buildtools.gradle.dsl.NativeResourcesOptions': error writing value of type 'org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions'
   > Configuration cache state could not be cached: field '__configurationFileDirectories__' from type 'org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions': error writing value of type 'org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection'
      > Configuration cache state could not be cached: field 'provider' from type 'org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec': error writing value of type 'org.gradle.api.internal.provider.FlatMapProvider'
         > Configuration cache state could not be cached: field 'transformer' from type 'org.gradle.api.internal.provider.TransformBackedProvider': error writing value of type 'org.graalvm.buildtools.gradle.NativeImagePlugin$$Lambda$1256/0x000000080155dc28'
            > Configuration cache state could not be cached: field 'capturedArgs' from type 'java.lang.invoke.SerializedLambda': error writing value of type '[Ljava.lang.Object;'
               > Unable to make field private final java.util.function.BiConsumer java.util.stream.Collectors$CollectorImpl.accumulator accessible: module java.base does not "opens java.util.stream" to unnamed module @bbf12e9

* 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
Configuration cache entry discarded.

I don't see the failure with 0.9.14. It occurs with 0.9.15 and 0.9.16-SNAPSHOT.

nbt-configuration-cache-problem.zip contains a reproducer that should fail as above.

@melix
Copy link
Collaborator

melix commented Oct 17, 2022

Thanks for the reproducer! 👀

@melix
Copy link
Collaborator

melix commented Oct 17, 2022

It seems we're actually hitting a Gradle bug here :/ I'm trying to see if we can workaround.

melix added a commit that referenced this issue Oct 17, 2022
This is an attempt to fix #338
@melix
Copy link
Collaborator

melix commented Oct 17, 2022

How critical is this for you? I'm afraid I'm hitting wall after wall, there seem to be bugs in Gradle I can't workaround :(

Latest problem is:

Caused by: java.io.InvalidObjectException: ReflectiveOperationException during deserialization
        ... 168 more
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        ... 168 more
Caused by: java.lang.ClassCastException: class org.gradle.api.internal.file.DefaultFileCollectionFactory$ResolvingFileCollection cannot be cast to class org.gradle.api.artifacts.Configuration (org.gradle.api.internal.file.DefaultFileCollectionFactory$ResolvingFileCollection and org.gradle.api.artifacts.Configuration are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @4cdf35a9)
        at org.graalvm.buildtools.gradle.NativeImagePlugin.$renamedDeserializeLambda$(NativeImagePlugin.java:154)
        at org.graalvm.buildtools.gradle.NativeImagePlugin.$deserializeLambda$(NativeImagePlugin.java)
        ... 171 more

Happening when the cache is deserialized.

@wilkinsona
Copy link
Author

Thanks for trying, @melix. It's not hugely critical. We have some users who care about the configuration cache but they're definitely a minority. I've disabled the failing test that alerted me to the problem so we're not blocked. Let's revisit this when there's more time to do so.

@sdeleuze sdeleuze removed this from the 0.9.16 milestone Oct 17, 2022
melix added a commit that referenced this issue Oct 18, 2022
This is an attempt to fix #338
@shoaniki
Copy link

shoaniki commented Nov 9, 2022

This isn't a showstopper by any means, but it is causing a certain amount of pain -- we've recently put some effort into fixing our build to support the configuration cache, and this is one of the few issues preventing us turning it on globally.

Just realised as I was typing this that #339 hasn't been merged yet – is it worth trying with that patch, or are the Gradle problems more deep-rooted than that?

@melix
Copy link
Collaborator

melix commented Nov 14, 2022

is it worth trying with that patch, or are the Gradle problems more deep-rooted than that?

The patch isn't enough. There are other problems arising which have no solution yet in Gradle.

@shoaniki
Copy link

That's disappointing, but good to know, thank you.
(Are there any relevant Gradle issues I can follow?)

@melix
Copy link
Collaborator

melix commented Mar 14, 2023

I took another stab at it and I think I fixed it in #339, but it will require bumping the minimal version of Gradle to 7.4 (for the plugin, independently of the config cache) and 7.5 (with the configuration cache).

melix added a commit that referenced this issue Mar 15, 2023
* Use serializable lambdas

This is an attempt to fix #338

* Fix compatibility with the configuration cache

In the process, this commit removes use of deprecated Gradle APIs
and therefore bumps the minimal version of Gradle to 7.4. The
configuration cache tests only pass on Gradle 7.5+, which is
reasonable given that it's an experimental feature.

* Disable test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants