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 Configuration Cache with Gradle 8.1 #221

Open
hfhbd opened this issue May 15, 2023 · 12 comments
Open

Support Configuration Cache with Gradle 8.1 #221

hfhbd opened this issue May 15, 2023 · 12 comments

Comments

@hfhbd
Copy link

hfhbd commented May 15, 2023

AFAIK this is my first release after updating Gradle to 8.1.1: https://scans.gradle.com/s/rdlhgp2eynkr4
The build contains ~30 jvm only modules.

@szpak
Copy link
Contributor

szpak commented May 15, 2023

Thanks for the build scan. Do you have a corresponding scan with 8.0? I assume, the release process worked fine with 8.0?

@szpak
Copy link
Contributor

szpak commented May 15, 2023

io.github.gradle-nexus.publish-plugin | 1.1.0

Please upgrade to 1.3.0. In 1.2.0 there were some deprecation warnings fixed.

@hfhbd
Copy link
Author

hfhbd commented May 16, 2023

Thank you for the fast response.
I updated the plugin to 1.3.0 but still get failures during storing the build cache.

Gradle 8.1.1 and Configuration Cache enabled: failure: https://scans.gradle.com/s/h5sldg3zjwzec
Gradle 8.1.1 and Configuration Cache disabled: success
Gradle 8.1.1 and Configuration Cache enabled: failure: https://scans.gradle.com/s/vcjket7g2mupe
Gradle 8.0.2 and Configuration Cache disabled: success

The failure with Gradle 8 was primary due the missing signing support, which was fixed with Gradle 8.1.
This release unblocked the configuration cache, so I tried it out, but now nexus fails.

@szpak
Copy link
Contributor

szpak commented May 16, 2023

Yes, I see that 8.1 helped with many issues in the Gradle core plugins. I had a quick look at the remaining output and:

Task :closeSonatypeStagingRepository of type io.github.gradlenexus.publishplugin.CloseNexusStagingRepository: cannot serialize object of type 'org.gradle.api.DefaultTask', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.

seems to be caused by the fact that our tasks effectively extends org.gradle.api.DefaultTask which (as of 8.0.2) is defined as:

@DisableCachingByDefault(because = "Gradle would require more information to cache this task")
public abstract class DefaultTask extends org.gradle.api.internal.AbstractTask implements Task { ... }

The javadoc for that annotation states:

 * <p>Caching for individual task instances can be enabled and disabled via {@link TaskOutputs#cacheIf(String, Spec)} or disabled via {@link TaskOutputs#doNotCacheIf(String, Spec)}.
 * Using these APIs takes precedence over the presence (or absence) of {@code @DisableCachingByDefault}.</p>

Could you use cacheIf for all the tasks from this plugin to enforce it and check if it helped (then they could be marked as cache'able by default).

Btw, does the project build and release fine with 8.1 if gradle --configuration-cache-problems=warn is used? I wonder if:

No staging repository with name sonatype created

is caused by the issues with cache or something else.

@hfhbd
Copy link
Author

hfhbd commented May 17, 2023

I don't get it: cacheIf is about enabling the build cache, which is independent of the configuration cache. Ideally, both caches are supported by this plugin, but they are not connected and could be enabled independently.

I fixed the No staging repository with name sonatype created error. There was a very strange error in combination with another plugin, so I fixed the other plugin.

Now I "just" get the error, the nexus plugin isn't compatible with the config cache:

https://scans.gradle.com/s/cucwn35lmbmuo

I will upload the configuration cache error file soon.

@hfhbd
Copy link
Author

hfhbd commented May 17, 2023

Added the configuration cache html report for this build scan https://gradle.com/s/cqgbqyvimhm2c
configuration-cache-report.html.txt
You have to remove the txt suffix, because GitHub does not allow uploading html files.

TWiStErRob added a commit to TWiStErRob/repros that referenced this issue May 25, 2023
@TWiStErRob
Copy link
Collaborator

TWiStErRob commented May 25, 2023

I had a quick look out of curiosity, I haven't got too far, but here's my thoughts anyway:

Investigation

Looking at the HTML and expanding first tree element fully I still see:

Caused by: java.lang.IllegalStateException: No staging repository with name sonatype created
at io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistry.get(StagingRepositoryDescriptorRegistry.kt:29)

Based on that I think this lazy value:

project.the<PublishingExtension>().repositories.maven {
name = nexusRepo.name
setUrl(
project.provider {
getRepoUrl(nexusRepo, extension, registry)
}
)

is being queried in order to store the configuration cache, but that probably shouldn't happen.

I have a feeling even if this exception wasn't thrown here the problem of serializing Tasks will come up.

Note: is Cached<PublishSpec> spec really necessary? Seems to me that the first line of publish() could be replaced:

-PublishSpec spec = this.spec.get()`
+PublishSpec spec = computeSpec()

and the field removed. EDIT: oh! this is Gradle task, not from this plugin, so the next question is even more relevant:

But even if that solves a problem, why is an instance of PublishToMavenRepository being serialized?

I also made a repro project:

(Dry run will not execute tasks, because the Nexus setup is bogus, but that doesn't matter because we want to test the code that runs before the EXECUTION phase.)

To consume a local build add to settings.gradle.kts: pluginManagement.repositories.mavenLocal() and change the plugin version to -SNAPSHOT.

@TWiStErRob
Copy link
Collaborator

I dug much deeper into the problems listed here are some findings:

  1. Each warning could be addressed individually leading overall more idiomatic Gradle plugin design, almost all the changes can be done without breaking any APIs!
    (if you count making (theoretically internal but public nonetheless) classes abstract as non-breaking 😅)
    I think these improvements can be discussed and done gradually independent of this CC issue.
    Improvements can be found as commits here:
    https://github.com/TWiStErRob/nexus-publish-gradle-plugin/commits/configuration-cache-induced-idiomatic-gradle-improvements

  2. I went to find the minimum set of changes to fix most of the problems and ended up with Fix most of configuration cache warnings #223

  3. The biggest problem is the error that is now cleanly reproducible with my repro above.

    error writing value of type org.gradle.api.publish.maven.tasks.PublishToMavenRepository$RepositorySpec$Configured
    error writing value of type org.gradle.api.publish.maven.tasks.PublishToMavenRepository$RepositorySpec$Configured📋
    ⌄fieldrepository📋 of org.gradle.api.publish.maven.tasks.PublishToMavenRepository$PublishSpec📋
    ⌄bean of type org.gradle.api.publish.maven.tasks.PublishToMavenRepository$PublishSpec📋
    ⌄fieldvalue📋 of org.gradle.internal.Try$Success📋
    ⌄bean of type org.gradle.internal.Try$Success📋
    ⌄fieldresult📋 of org.gradle.internal.serialization.Cached$Fixed📋
    ⌄bean of type org.gradle.internal.serialization.Cached$Fixed📋
    ⌄fieldspec📋 of org.gradle.api.publish.maven.tasks.PublishToMavenRepository📋
    ⌄task:publishMavenJavaPublicationToMyNexusRepository📋 of type org.gradle.api.publish.maven.tasks.PublishToMavenRepository📋
    ⌄exception stack trace 📋
    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)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    	at org.gradle.configurationcache.serialization.codecs.jos.JavaObjectSerializationCodec$WriteReplaceEncoding.encode(JavaObjectSerializationCodec.kt:158)
    	at org.gradle.configurationcache.serialization.codecs.BindingsBackedCodec.encode(BindingsBackedCodec.kt:52)
    	at org.gradle.configurationcache.serialization.DefaultWriteContext.write(Contexts.kt:87)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriterKt.writeNextProperty(BeanPropertyWriter.kt:98)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriter.writeStateOf(BeanPropertyWriter.kt:53)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriter$writeStateOf$1.invokeSuspend(BeanPropertyWriter.kt)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlin.coroutines.SafeContinuation.resumeWith(SafeContinuationJvm.kt:41)
    	at org.gradle.configurationcache.serialization.CombinatorsKt$reentrant$1$encodeLoop$$inlined$Continuation$1.resumeWith(Continuation.kt:167)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    	at kotlin.coroutines.SafeContinuation.resumeWith(SafeContinuationJvm.kt:41)
    	at org.gradle.configurationcache.serialization.CombinatorsKt$reentrant$1$encodeLoop$$inlined$Continuation$1.resumeWith(Continuation.kt:167)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    	at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)
    	at org.gradle.configurationcache.serialization.CombinatorsKt$reentrant$1.encodeLoop(Combinators.kt:146)
    	at org.gradle.configurationcache.serialization.CombinatorsKt$reentrant$1.encode(Combinators.kt:116)
    	at org.gradle.configurationcache.serialization.codecs.BindingsBackedCodec.encode(BindingsBackedCodec.kt:52)
    	at org.gradle.configurationcache.serialization.DefaultWriteContext.write(Contexts.kt:87)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriterKt.writeNextProperty(BeanPropertyWriter.kt:98)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriter.writeStateOf(BeanPropertyWriter.kt:53)
    	at org.gradle.configurationcache.serialization.CodecKt.encodeBean(Codec.kt:318)
    	at org.gradle.configurationcache.serialization.codecs.jos.JavaObjectSerializationCodec$WriteReplaceEncoding.encode(JavaObjectSerializationCodec.kt:166)
    	at org.gradle.configurationcache.serialization.codecs.BindingsBackedCodec.encode(BindingsBackedCodec.kt:52)
    	at org.gradle.configurationcache.serialization.DefaultWriteContext.write(Contexts.kt:87)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriterKt.writeNextProperty(BeanPropertyWriter.kt:98)
    	at org.gradle.configurationcache.serialization.beans.BeanPropertyWriter.writeStateOf(BeanPropertyWriter.kt:53)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodec$writeTask$3$2$1.invokeSuspend(TaskNodeCodec.kt:103)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodec$writeTask$3$2$1.invoke(TaskNodeCodec.kt)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodec$writeTask$3$2$1.invoke(TaskNodeCodec.kt)
    	at org.gradle.configurationcache.serialization.AbstractIsolateContext.forIncompatibleType$suspendImpl(Contexts.kt:425)
    	at org.gradle.configurationcache.serialization.AbstractIsolateContext.forIncompatibleType(Contexts.kt)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodecKt.withTaskOf(TaskNodeCodec.kt:237)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodecKt.access$withTaskOf(TaskNodeCodec.kt:1)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodec.writeTask(TaskNodeCodec.kt:97)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodec.encode(TaskNodeCodec.kt:74)
    	at org.gradle.configurationcache.serialization.codecs.TaskNodeCodec.encode(TaskNodeCodec.kt:67)
    	at org.gradle.configurationcache.serialization.codecs.BindingsBackedCodec.encode(BindingsBackedCodec.kt:52)
    	at org.gradle.configurationcache.serialization.DefaultWriteContext.write(Contexts.kt:87)
    	at org.gradle.configurationcache.serialization.codecs.WorkNodeCodec.writeNodes(WorkNodeCodec.kt:68)
    	at org.gradle.configurationcache.serialization.codecs.WorkNodeCodec.writeWork(WorkNodeCodec.kt:53)
    	at org.gradle.configurationcache.ConfigurationCacheState.writeWorkGraphOf(ConfigurationCacheState.kt:448)
    	at org.gradle.configurationcache.ConfigurationCacheState.writeBuildContent$configuration_cache(ConfigurationCacheState.kt:409)
    	at org.gradle.configurationcache.ConfigurationCacheState.writeBuildState(ConfigurationCacheState.kt:276)
    	at org.gradle.configurationcache.ConfigurationCacheState.writeBuildsInTree(ConfigurationCacheState.kt:248)
    	at org.gradle.configurationcache.ConfigurationCacheState.writeRootBuild(ConfigurationCacheState.kt:223)
    	at org.gradle.configurationcache.ConfigurationCacheState.writeRootBuildState(ConfigurationCacheState.kt:144)
    	at org.gradle.configurationcache.ConfigurationCacheIO$writeRootBuildStateTo$1.invokeSuspend(ConfigurationCacheIO.kt:138)
    	at org.gradle.configurationcache.ConfigurationCacheIO$writeRootBuildStateTo$1.invoke(ConfigurationCacheIO.kt)
    	at org.gradle.configurationcache.ConfigurationCacheIO$writeRootBuildStateTo$1.invoke(ConfigurationCacheIO.kt)
    	at org.gradle.configurationcache.ConfigurationCacheIO$writeConfigurationCacheState$2$1.invokeSuspend(ConfigurationCacheIO.kt:190)
    	at org.gradle.configurationcache.ConfigurationCacheIO$writeConfigurationCacheState$2$1.invoke(ConfigurationCacheIO.kt)
    	at org.gradle.configurationcache.ConfigurationCacheIO$writeConfigurationCacheState$2$1.invoke(ConfigurationCacheIO.kt)
    	at org.gradle.configurationcache.serialization.RunningKt$runWriteOperation$1.invokeSuspend(Running.kt:45)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)
    	at org.gradle.configurationcache.serialization.RunningKt.runToCompletion(Running.kt:56)
    	at org.gradle.configurationcache.serialization.RunningKt.runWriteOperation(Running.kt:44)
    	at org.gradle.configurationcache.ConfigurationCacheIO.writeConfigurationCacheState(ConfigurationCacheIO.kt:189)
    	at org.gradle.configurationcache.ConfigurationCacheIO.writeRootBuildStateTo$configuration_cache(ConfigurationCacheIO.kt:136)
    	at org.gradle.configurationcache.DefaultConfigurationCache$writeConfigurationCacheState$1.run(DefaultConfigurationCache.kt:398)
    	at org.gradle.internal.Factories$1.create(Factories.java:31)
    	at org.gradle.internal.work.DefaultWorkerLeaseService.withReplacedLocks(DefaultWorkerLeaseService.java:345)
    	at org.gradle.api.internal.project.DefaultProjectStateRegistry$DefaultBuildProjectRegistry.withMutableStateOfAllProjects(DefaultProjectStateRegistry.java:228)
    	at org.gradle.api.internal.project.DefaultProjectStateRegistry$DefaultBuildProjectRegistry.withMutableStateOfAllProjects(DefaultProjectStateRegistry.java:221)
    	at org.gradle.configurationcache.DefaultConfigurationCache.writeConfigurationCacheState(DefaultConfigurationCache.kt:397)
    	at org.gradle.configurationcache.DefaultConfigurationCache.access$writeConfigurationCacheState(DefaultConfigurationCache.kt:53)
    	at org.gradle.configurationcache.DefaultConfigurationCache$saveWorkGraph$1.invoke(DefaultConfigurationCache.kt:324)
    	at org.gradle.configurationcache.DefaultConfigurationCache$saveWorkGraph$1.invoke(DefaultConfigurationCache.kt:324)
    	at org.gradle.configurationcache.DefaultConfigurationCache$saveToCache$1$1.invoke(DefaultConfigurationCache.kt:340)
    	at org.gradle.configurationcache.DefaultConfigurationCache$saveToCache$1$1.invoke(DefaultConfigurationCache.kt:338)
    	at org.gradle.configurationcache.ConfigurationCacheRepository$StoreImpl$useForStore$1.invoke(ConfigurationCacheRepository.kt:192)
    	at org.gradle.configurationcache.ConfigurationCacheRepository$StoreImpl$useForStore$1.invoke(ConfigurationCacheRepository.kt:184)
    	at org.gradle.configurationcache.ConfigurationCacheRepository$withExclusiveAccessToCache$1.create(ConfigurationCacheRepository.kt:261)
    	at org.gradle.cache.internal.LockOnDemandCrossProcessCacheAccess.withFileLock(LockOnDemandCrossProcessCacheAccess.java:90)
    	at org.gradle.cache.internal.DefaultCacheCoordinator.withFileLock(DefaultCacheCoordinator.java:219)
    	at org.gradle.cache.internal.DefaultPersistentDirectoryStore.withFileLock(DefaultPersistentDirectoryStore.java:188)
    	at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.withFileLock(DefaultCacheFactory.java:214)
    	at org.gradle.configurationcache.ConfigurationCacheRepository.withExclusiveAccessToCache(ConfigurationCacheRepository.kt:259)
    	at org.gradle.configurationcache.ConfigurationCacheRepository.access$withExclusiveAccessToCache(ConfigurationCacheRepository.kt:50)
    	at org.gradle.configurationcache.ConfigurationCacheRepository$StoreImpl.useForStore(ConfigurationCacheRepository.kt:184)
    	at org.gradle.configurationcache.DefaultConfigurationCache$saveToCache$1.invoke(DefaultConfigurationCache.kt:338)
    	at org.gradle.configurationcache.DefaultConfigurationCache$saveToCache$1.invoke(DefaultConfigurationCache.kt:337)
    	at org.gradle.configurationcache.ConfigurationCacheBuildOperationsKt$withOperation$1.call(ConfigurationCacheBuildOperations.kt:60)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
    	at org.gradle.configurationcache.ConfigurationCacheBuildOperationsKt.withOperation(ConfigurationCacheBuildOperations.kt:55)
    	at org.gradle.configurationcache.ConfigurationCacheBuildOperationsKt.withStoreOperation(ConfigurationCacheBuildOperations.kt:34)
    	at org.gradle.configurationcache.DefaultConfigurationCache.saveToCache(DefaultConfigurationCache.kt:337)
    	at org.gradle.configurationcache.DefaultConfigurationCache.saveWorkGraph(DefaultConfigurationCache.kt:324)
    	at org.gradle.configurationcache.DefaultConfigurationCache.access$saveWorkGraph(DefaultConfigurationCache.kt:53)
    	at org.gradle.configurationcache.DefaultConfigurationCache$loadOrScheduleRequestedTasks$1.invoke(DefaultConfigurationCache.kt:135)
    	at org.gradle.configurationcache.DefaultConfigurationCache$loadOrScheduleRequestedTasks$1.invoke(DefaultConfigurationCache.kt:133)
    	at org.gradle.configurationcache.DefaultConfigurationCache.runWorkThatContributesToCacheEntry(DefaultConfigurationCache.kt:296)
    	at org.gradle.configurationcache.DefaultConfigurationCache.loadOrScheduleRequestedTasks(DefaultConfigurationCache.kt:133)
    	at org.gradle.configurationcache.ConfigurationCacheAwareBuildTreeWorkController$scheduleAndRunRequestedTasks$executionResult$1.apply(ConfigurationCacheAwareBuildTreeWorkController.kt:40)
    	at org.gradle.configurationcache.ConfigurationCacheAwareBuildTreeWorkController$scheduleAndRunRequestedTasks$executionResult$1.apply(ConfigurationCacheAwareBuildTreeWorkController.kt:39)
    	at org.gradle.composite.internal.DefaultIncludedBuildTaskGraph.withNewWorkGraph(DefaultIncludedBuildTaskGraph.java:109)
    	at org.gradle.configurationcache.ConfigurationCacheAwareBuildTreeWorkController.scheduleAndRunRequestedTasks(ConfigurationCacheAwareBuildTreeWorkController.kt:39)
    	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.lambda$scheduleAndRunTasks$1(DefaultBuildTreeLifecycleController.java:68)
    	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.lambda$runBuild$4(DefaultBuildTreeLifecycleController.java:98)
    	at org.gradle.internal.model.StateTransitionController.lambda$transition$6(StateTransitionController.java:169)
    	at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:266)
    	at org.gradle.internal.model.StateTransitionController.lambda$transition$7(StateTransitionController.java:169)
    	at org.gradle.internal.work.DefaultSynchronizer.withLock(DefaultSynchronizer.java:44)
    	at org.gradle.internal.model.StateTransitionController.transition(StateTransitionController.java:169)
    	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.runBuild(DefaultBuildTreeLifecycleController.java:95)
    	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.scheduleAndRunTasks(DefaultBuildTreeLifecycleController.java:68)
    	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.scheduleAndRunTasks(DefaultBuildTreeLifecycleController.java:63)
    	at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:31)
    	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    	at org.gradle.internal.buildtree.ProblemReportingBuildActionRunner.run(ProblemReportingBuildActionRunner.java:49)
    	at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:65)
    	at org.gradle.tooling.internal.provider.FileSystemWatchingBuildActionRunner.run(FileSystemWatchingBuildActionRunner.java:140)
    	at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:41)
    	at org.gradle.launcher.exec.RootBuildLifecycleBuildActionExecutor.lambda$execute$0(RootBuildLifecycleBuildActionExecutor.java:40)
    	at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:122)
    	at org.gradle.launcher.exec.RootBuildLifecycleBuildActionExecutor.execute(RootBuildLifecycleBuildActionExecutor.java:40)
    	at org.gradle.internal.buildtree.InitDeprecationLoggingActionExecutor.execute(InitDeprecationLoggingActionExecutor.java:58)
    	at org.gradle.internal.buildtree.DefaultBuildTreeContext.execute(DefaultBuildTreeContext.java:40)
    	at org.gradle.launcher.exec.BuildTreeLifecycleBuildActionExecutor.lambda$execute$0(BuildTreeLifecycleBuildActionExecutor.java:65)
    	at org.gradle.internal.buildtree.BuildTreeState.run(BuildTreeState.java:53)
    	at org.gradle.launcher.exec.BuildTreeLifecycleBuildActionExecutor.execute(BuildTreeLifecycleBuildActionExecutor.java:65)
    	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor$3.call(RunAsBuildOperationBuildActionExecutor.java:61)
    	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor$3.call(RunAsBuildOperationBuildActionExecutor.java:57)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
    	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor.execute(RunAsBuildOperationBuildActionExecutor.java:57)
    	at org.gradle.launcher.exec.RunAsWorkerThreadBuildActionExecutor.lambda$execute$0(RunAsWorkerThreadBuildActionExecutor.java:36)
    	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:249)
    	at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:109)
    	at org.gradle.launcher.exec.RunAsWorkerThreadBuildActionExecutor.execute(RunAsWorkerThreadBuildActionExecutor.java:36)
    	at org.gradle.tooling.internal.provider.continuous.ContinuousBuildActionExecutor.execute(ContinuousBuildActionExecutor.java:110)
    	at org.gradle.tooling.internal.provider.SubscribableBuildActionExecutor.execute(SubscribableBuildActionExecutor.java:64)
    	at org.gradle.internal.session.DefaultBuildSessionContext.execute(DefaultBuildSessionContext.java:46)
    	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter$ActionImpl.apply(BuildSessionLifecycleBuildActionExecuter.java:100)
    	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter$ActionImpl.apply(BuildSessionLifecycleBuildActionExecuter.java:88)
    	at org.gradle.internal.session.BuildSessionState.run(BuildSessionState.java:69)
    	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter.execute(BuildSessionLifecycleBuildActionExecuter.java:62)
    	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter.execute(BuildSessionLifecycleBuildActionExecuter.java:41)
    	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
    	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
    	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:50)
    	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:38)
    	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:47)
    	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:31)
    	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:65)
    	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:29)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
    	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
    	at org.gradle.util.internal.Swapper.swap(Swapper.java:38)
    	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:64)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
    	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:84)
    	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
    	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    	at java.base/java.lang.Thread.run(Thread.java:833)
    Caused by: java.lang.IllegalStateException: No staging repository with name myNexus created
    	at io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistry.get(StagingRepositoryDescriptorRegistry.kt:29)
    	at io.github.gradlenexus.publishplugin.NexusPublishPlugin.getRepoUrl(NexusPublishPlugin.kt:240)
    	at io.github.gradlenexus.publishplugin.NexusPublishPlugin.access$getRepoUrl(NexusPublishPlugin.kt:40)
    	at io.github.gradlenexus.publishplugin.NexusPublishPlugin$addMavenRepositories$$inlined$associateWith$lambda$1$1.call(NexusPublishPlugin.kt:187)
    	at io.github.gradlenexus.publishplugin.NexusPublishPlugin$addMavenRepositories$$inlined$associateWith$lambda$1$1.call(NexusPublishPlugin.kt:40)
    	at org.gradle.api.internal.provider.DefaultProvider.calculateOwnValue(DefaultProvider.java:72)
    	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateOwnPresentValue(AbstractMinimalProvider.java:73)
    	at org.gradle.api.internal.provider.AbstractMinimalProvider.get(AbstractMinimalProvider.java:93)
    	at org.gradle.api.internal.provider.ProviderResolutionStrategy$2.resolve(ProviderResolutionStrategy.java:33)
    	at org.gradle.util.internal.DeferredUtil.unpack(DeferredUtil.java:59)
    	at org.gradle.util.internal.DeferredUtil.unpack(DeferredUtil.java:38)
    	at org.gradle.api.internal.file.AbstractFileResolver.convertObjectToURI(AbstractFileResolver.java:91)
    	at org.gradle.api.internal.file.AbstractFileResolver.resolveUri(AbstractFileResolver.java:85)
    	at org.gradle.api.internal.artifacts.repositories.DefaultUrlArtifactRepository.getUrl(DefaultUrlArtifactRepository.java:53)
    	at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.getUrl(DefaultMavenArtifactRepository.java:172)
    	at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated.getUrl(Unknown Source)
    	at org.gradle.api.publish.maven.tasks.PublishToMavenRepository$RepositorySpec$Configured.writeReplace(PublishToMavenRepository.java:169)
    	... 190 more
    

If we filter the stack trace it makes more sense:

error writing value of type org.gradle.api.publish.maven.tasks.PublishToMavenRepository$RepositorySpec$Configured📋
⌄field spec📋 of org.gradle.api.publish.maven.tasks.PublishToMavenRepository📋
⌄task:publishMavenJavaPublicationToMyNexusRepository📋 of type org.gradle.api.publish.maven.tasks.PublishToMavenRepository📋

java.lang.reflect.InvocationTargetException
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.configurationcache.serialization.codecs.jos.JavaObjectSerializationCodec$WriteReplaceEncoding.encode(JavaObjectSerializationCodec.kt:158)
Caused by: java.lang.IllegalStateException: No staging repository with name myNexus created
	at io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistry.get(StagingRepositoryDescriptorRegistry.kt:29)
	at io.github.gradlenexus.publishplugin.NexusPublishPlugin.getRepoUrl(NexusPublishPlugin.kt:240)
	at io.github.gradlenexus.publishplugin.NexusPublishPlugin$addMavenRepositories$$inlined$associateWith$lambda$1$1.call(NexusPublishPlugin.kt:187)
	at io.github.gradlenexus.publishplugin.NexusPublishPlugin$addMavenRepositories$$inlined$associateWith$lambda$1$1.call(NexusPublishPlugin.kt:40)
	at org.gradle.api.internal.provider.DefaultProvider.calculateOwnValue(DefaultProvider.java:72)
	at org.gradle.api.internal.artifacts.repositories.DefaultUrlArtifactRepository.getUrl(DefaultUrlArtifactRepository.java:53)
	at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.getUrl(DefaultMavenArtifactRepository.java:172)
	at org.gradle.api.publish.maven.tasks.PublishToMavenRepository$RepositorySpec$Configured.writeReplace(PublishToMavenRepository.java:169)
	... 190 more

The key here is that in order to serialize the repository, we need to have its URL ready. But the URL is only available after a task that initializes the repository has been executed. This is where I need domain knowledge help @szpak: is it possible to add these repositories after their URLs are resolved? I think the root cause here is that NexusPublishPlugin.addMavenRepositories creates publishing.repositories before their URLs are known.

@TWiStErRob
Copy link
Collaborator

I think another root cause of this error seems to be that

Maven Publish plugin is partially supported.

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

image

They might be referring to this problem with that warning icon. @hfhbd What do you think, what's your read of the my findings? Based on this any change to this plugin might be just a workaround / hack of Gradle partial support.

@hfhbd
Copy link
Author

hfhbd commented May 25, 2023

Thanks for the analysis.
I think, I agree: #223 would fix some warnings, but there are still some errors due to maven-publish missing support, looks like gradle/gradle#22779.
But I would still merge #223 to fix the warning.

@szpak
Copy link
Contributor

szpak commented May 25, 2023

@TWiStErRob Thanks for your insightful analysis!

is it possible to add these repositories after their URLs are resolved? I think the root cause here is that NexusPublishPlugin.addMavenRepositories creates publishing.repositories before their URLs are known.

I would be problematic. For every repository the tasks are created:

val nexusRepositories = addMavenRepositories(publishingProject, extension, registry)
nexusRepositories.forEach { (nexusRepo, mavenRepo) ->
val initializeTask = rootProject.tasks.named<InitializeNexusStagingRepository>("initialize${nexusRepo.capitalizedName}StagingRepository")
val findStagingRepositoryTask = rootProject.tasks.named<FindStagingRepository>("find${nexusRepo.capitalizedName}StagingRepository")
val closeTask = rootProject.tasks.named<CloseNexusStagingRepository>("close${nexusRepo.capitalizedName}StagingRepository")
val releaseTask = rootProject.tasks.named<ReleaseNexusStagingRepository>("release${nexusRepo.capitalizedName}StagingRepository")
val publishAllTask = publishingProject.tasks.register("publishTo${nexusRepo.capitalizedName}") {
description = "Publishes all Maven publications produced by this project to the '${nexusRepo.name}' Nexus repository."
group = PublishingPlugin.PUBLISH_TASK_GROUP
}
closeTask {
mustRunAfter(publishAllTask)
}
releaseTask {
mustRunAfter(publishAllTask)
}
configureTaskDependencies(publishingProject, initializeTask, findStagingRepositoryTask, publishAllTask, closeTask, releaseTask, mavenRepo)
}

The tasks (and their orchestration) cannot be created after the execution of the initialization task, so we could need to have some "temporal structure" without URL to have it serialized and somehow add and keep the URL later on there it is needed. gradle/gradle#22779 should solve it in a better way.

#223 looks good, I will merge it right after a bigger #222 to avoid potential conflicts there.

@TWiStErRob
Copy link
Collaborator

Update: gradle/gradle#22779 is scheduled for Gradle 9 (for now).

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

No branches or pull requests

3 participants