moko-resources
moko-resources copied to clipboard
Support for Gradle configuration cache
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
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
Any info on when this will be fixed? I'd really like to use this in my current project.
@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?
@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
Any updates on it?
if moko-resource can support gradle caching it would be great, It can greatly accelerate app development.
@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?
@lepicekmichal is there any way to disable cache configuration for moko-resource?
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)
@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 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
There is no real alternative sadly. We made our own translation object in the code and the rest of resources are still in progress
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.
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
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 moko resources tasks run with assemble and so on, it would be the same as disabling the configuration cache.
@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.
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).
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.
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.
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.
@Alex009 Is this something that's planned?
fix in #575
will be fixed in 0.24.0, please check in 0.24.0-alpha-6
fixed in 0.24.0-beta-1