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

Support for Gradle configuration cache #311

Closed
JackHurst0 opened this issue Mar 4, 2022 · 25 comments
Closed

Support for Gradle configuration cache #311

JackHurst0 opened this issue Mar 4, 2022 · 25 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@JackHurst0
Copy link

It's not possible to enable Gradle configuration Cache in projects using moko-resources

For example in the demo project, update the root gradle.properties file:

org.gradle.jvmargs=-Xmx8g
org.gradle.parallel=true
# Enable Configuration Cache
org.gradle.unsafe.configuration-cache=true

kotlin.code.style=official

kotlin.mpp.stability.nowarn=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCompatibilityMetadataVariant=true

android.useAndroidX=true

xcodeproj=./sample/ios-app

mobile.multiplatform.iosTargetWarning=false

Then running ./gradlew :sample:android-app:assembleDebug
You will see many errors:

572 problems were found storing the configuration cache, 45 of which seem unique.
- Task `:sample:mpp-library:generateMRandroidMain` of type `dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask`: cannot serialize object of type 'org.gradle.accessors.dm.ResourcesProjectDependency', a subtype of 'org.gradle.api.artifacts.Dependency', as these are not supported with the configuration cache.
  See https://docs.gradle.org/7.3.3/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:sample:mpp-library:generateMRandroidMain` of type `dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask`: cannot serialize object of type 'org.gradle.accessors.dm.Sample_MppLibrary_NestedModuleProjectDependency', a subtype of 'org.gradle.api.artifacts.Dependency', as these are not supported with the configuration cache.
  See https://docs.gradle.org/7.3.3/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
...

It looks like this happens because there are tasks in the project that reference several of the types that are disallowed by gradle configuration cache. See disallowed types

@Alex009 Alex009 added enhancement New feature or request help wanted Extra attention is needed labels Mar 5, 2022
@lepicekmichal
Copy link

same problem here

20 problems were found storing the configuration cache, 4 of which seem unique.
- Task `:shared:shoppingListApi:generateMRandroidMain` of type `dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask`: cannot serialize object of type 'org.gradle.api.internal.file.DefaultSourceDirectorySet', a subtype of 'org.gradle.api.file.SourceDirectorySet', as these are not supported with the configuration cache.
  See https://docs.gradle.org/7.4/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:shared:shoppingListApi:generateMRandroidMain` of type `dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
  See https://docs.gradle.org/7.4/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:shared:shoppingListApi:generateMRcommonMain` of type `dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask`: cannot serialize object of type 'org.gradle.api.internal.file.DefaultSourceDirectorySet', a subtype of 'org.gradle.api.file.SourceDirectorySet', as these are not supported with the configuration cache.
  See https://docs.gradle.org/7.4/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:shared:shoppingListApi:generateMRcommonMain` of type `dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
  See https://docs.gradle.org/7.4/userguide/configuration_cache.html#config_cache:requirements:disallowed_types

@ThomasGoehringer
Copy link

Any info on when this will be fixed? I'd really like to use this in my current project.

@Alex009 Alex009 added this to the 0.20.0 milestone Mar 23, 2022
@Alex009 Alex009 removed this from the 0.20.0 milestone May 14, 2022
@lepicekmichal
Copy link

@Alex009 I would like to help (I have some experience with configuration cache), but I have zero knowledge about gradle plugins themselves. Can you help me with setting up local project so I can test it out?

@Alex009
Copy link
Member

Alex009 commented May 16, 2022

@lepicekmichal its good. Yes, I will help.
But all thing that you should do - just clone project and open :) gradle plugin added as gradle composite build. so you can test all changes without publishing

@Pschsch
Copy link

Pschsch commented Feb 15, 2023

Any updates on it?

@kazemcodes
Copy link

if moko-resource can support gradle caching it would be great, It can greatly accelerate app development.

@kazemcodes
Copy link

@Alex009 I would like to help (I have some experience with configuration cache), but I have zero knowledge about gradle plugins themselves. Can you help me with setting up local project so I can test it out?

Any update?

@kazemcodes
Copy link

@lepicekmichal is there any way to disable cache configuration for moko-resource?

@kazemcodes
Copy link

I have the same issue when I enable caching but with different error
Configuration cache state could not be cached: field singleStorage of com.android.build.api.artifact.impl.TypedStorageProvider bean found in field directory of com.android.build.api.artifact.impl.StorageProviderImpl bean found in field storageProvider of com.android.build.api.artifact.impl.ArtifactsImpl bean found in field artifacts of com.android.build.gradle.internal.variant.LibraryVariantData bean found in field testedVariantData of com.android.build.gradle.internal.variant.TestVariantData bean found in field variantData of com.android.build.gradle.internal.api.TestVariantImpl bean found in field testVariant of com.android.build.gradle.internal.api.LibraryVariantImpl bean found in field testedVariant of com.android.build.gradle.internal.api.UnitTestVariantImpl bean found in field androidVariant of org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation bean found in field underlying of org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl bean found in field compilations of org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet bean found in field sourceSetsAddedEagerly of org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCompilationDetailsWithRuntime bean found in field compilationDetails of org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation bean found in field compilation of org.jetbrains.kotlin.gradle.targets.jvm.SingleJvmCompilationTestRunSource bean found in field value of kotlin.properties.NotNullVar bean found in field _executionSource$delegate of org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTestRun bean found in field map of org.gradle.api.internal.DefaultNamedDomainObjectCollection$UnfilteredIndex bean found in field index of org.gradle.api.internal.FactoryNamedDomainObjectContainer bean found in field testRuns of org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget bean found in field target of org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCompilationDetailsWithRuntime bean found in field compilationDetails of org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation bean found in field underlying of org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl bean found in field compilations of org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet bean found in field $kotlinSourceSet of dev.icerock.gradle.MultiplatformResourcesPlugin$createSourceSet$1 bean found in field sourceSet of dev.icerock.gradle.generator.common.CommonMRGenerator bean found in field generator of task :i18n:generateMRcommonMain of type dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask: error writing value of type 'java.util.LinkedHashMap'

java.util.ConcurrentModificationException (no error message)

@lepicekmichal
Copy link

@kazemcodes sorry, we dropped it. So much work that we decided not to use moko-resources. It clearly hasn't been developed with conf cache in mind and doubt it ever will be.

As for disabling it, I'm not sure what you mean. Conf cache is a global thing and either all plugins support it or not, ergo you have it or not.

@kazemcodes
Copy link

@kazemcodes sorry, we dropped it. So much work that we decided not to use moko-resources. It clearly hasn't been developed with conf cache in mind and doubt it ever will be.

As for disabling it, I'm not sure what you mean. Conf cache is a global thing and either all plugins support it or not, ergo you have it or not.

What alternative do you choose instead of moko-resource

@lepicekmichal
Copy link

There is no real alternative sadly. We made our own translation object in the code and the rest of resources are still in progress

@kazemcodes
Copy link

there is new error for me
Configuration cache state could not be cached: field apiConfiguration of org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.DefaultKotlinCompilationConfigurationsContainer bean found in field dependencyConfigurations of org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl$Params bean found in field params of org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl bean found in field $$delegate_0 of org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation bean found in field underlying of org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl bean found in field compilations of org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet bean found in field $kotlinSourceSet of dev.icerock.gradle.MultiplatformResourcesPlugin$createSourceSet$1 bean found in field sourceSet of dev.icerock.gradle.generator.common.CommonMRGenerator bean found in field generator of task :i18n:generateMRcommonMain of type dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask: error writing value of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfiguration'

Resolving dependency configuration 'metadataCompilationApi' is not allowed as it is defined as 'canBeResolved=false'.
Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'metadataCompilationApi' should be resolved.

@Pschsch
Copy link

Pschsch commented Apr 28, 2023

Seems that it's need to fully rewrite resources generator plugin to support configuration cache by removing all references to non-serializable objects in moko resources tasks. It won't be easy walk

@colintheshots
Copy link

colintheshots commented May 22, 2023

Wouldn't it be sufficient for a temporary workaround to mark all moko-resources tasks as notCompatibleWithConfigurationCache("needs to be rewritten to remove all references to non-serializable objects... See moko-resources#311")?

This would allow library consumers to enable config cache, which is no longer unstable and will soon be default. Then they can benefit from the config cache for all other tasks without having their builds broken.

https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:task_opt_out

colintheshots-meetup added a commit to colintheshots-meetup/moko-resources that referenced this issue May 22, 2023
colintheshots-meetup added a commit to colintheshots-meetup/moko-resources that referenced this issue May 22, 2023
colintheshots-meetup added a commit to colintheshots-meetup/moko-resources that referenced this issue May 22, 2023
@JavierSegoviaCordoba
Copy link
Contributor

@colintheshots moko resources tasks run with assemble and so on, it would be the same as disabling the configuration cache.

@colintheshots
Copy link

colintheshots commented May 22, 2023

@JavierSegoviaCordoba So we'd prefer failing the build rather than disabling the configuration cache temporarily while fixing this? If so, it would be better to explicitly call out the issue in a throw block rather than making developers Google this.

@JavierSegoviaCordoba
Copy link
Contributor

JavierSegoviaCordoba commented May 22, 2023

it would be easier for the developer to understand the crash than they see how they lose the config cache on every run?

I am not sure if it is so hard to do a workaround to fix this by just injecting the properties from outside by extracting the code which is used inside the task to a provider outside the task, in a non-clean way (just copy-pasting + wrap in provider).

@colintheshots-meetup
Copy link
Contributor

I am not sure if it is so hard to do a workaround to fix this by just injecting the properties from outside by extracting the code which is used inside the task to a provider outside the task, in a non-clean way (just copy-pasting + wrap in provider).

I'll take a look at this option.

@Alex009 Alex009 linked a pull request May 23, 2023 that will close this issue
@colintheshots-meetup
Copy link
Contributor

I started looking into this over the weekend. This didn't appear to be a quick improvement. We're only expecting about a 13 second build speed improvement by fixing this at our company. I'm not sure the time spent is justified for us.

@ScottPierce
Copy link

Where did things land with this? This is the one issue that's stopping us from using the configuration cache.

We're only expecting about a 13 second build speed improvement by fixing this at our company

I'm not sure that this is the correct way to think about it. This is providing a significantly faster Gradle daemon startup time, is massive improvement to the dev experience.

Currently, in our ~150 module Gradle project, moko resources seems to be the one thing blocking us from turning on the configuration cache.

@ScottPierce
Copy link

@Alex009 Is this something that's planned?

@Alex009
Copy link
Member

Alex009 commented Jan 14, 2024

fix in #575

@Alex009 Alex009 added this to the 0.24.0 milestone Jan 14, 2024
@Alex009 Alex009 self-assigned this Jan 14, 2024
@ExNDY ExNDY removed the help wanted Extra attention is needed label Apr 17, 2024
@ExNDY
Copy link
Contributor

ExNDY commented Apr 17, 2024

will be fixed in 0.24.0, please check in 0.24.0-alpha-6

@Alex009
Copy link
Member

Alex009 commented Apr 19, 2024

fixed in 0.24.0-beta-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.