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

Allow publishing to a pre-defined staging repository #3562

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

IgnatBeresnev
Copy link
Member

Due to Gradle running publishing tasks in parallel, multiple staging repositories can be created within a couple of seconds with all artifact files scattered throughout them. Even though the publishing in done on the same build agent.

Interestingly enough, setting -Dorg.gradle.parallel=false didn't help, I believe it's due to us using included builds, but I'm not sure.

Setting --max-workers=1 additionally did help, but significant time was spent to find and test this solution.

Given it's easy to forget to set these params (especially when adding new build steps in TC), I think it's much easier to just allow to publish to a predefined staging repo, which will be created before the publishing build is run (as a prerequisite).

@adam-enko
Copy link
Member

Makes sense to me.

It'd also be worth replacing the config-cache disabler here

tasks.withType<PublishToMavenRepository>().configureEach {
// Configuration Cache allows tasks to run in parallel. Maven repositories (especially Maven Central)
// can't cope with parallel uploads, and might drop or split publications.
// As a workaround, disable Configuration Cache whenever publishing to remote Maven repos.
notCompatibleWithConfigurationCache("Prevent parallel publishing tasks")
}

And instead using a build service to limit task parallelization:

//region Maven Central can't handle parallel uploads, so limit parallel uploads with a service.
abstract class MavenPublishLimiter : BuildService<BuildServiceParameters.None>

val mavenPublishLimiter =
  gradle.sharedServices.registerIfAbsent("mavenPublishLimiter", MavenPublishLimiter::class) {
    maxParallelUsages = 1
  }

tasks.withType<PublishToMavenRepository>().configureEach {
  usesService(mavenPublishLimiter)
}
//endregion

@whyoleg
Copy link
Collaborator

whyoleg commented Apr 12, 2024

It'd also be worth replacing the config-cache disabler here

Good idea!
Additionally, AFAIU, this could be dropped at all when DOKKA_MVN_CENTRAL_REPOSITORY_ID is set, as there should be no issues then. Am I correct?

If so, something like this could be done instead:

//region Maven Central can't handle parallel uploads, so limit parallel uploads with a service.
abstract class MavenPublishLimiter : BuildService<BuildServiceParameters.None>

val mavenPublishLimiter =
  gradle.sharedServices.registerIfAbsent("mavenPublishLimiter", MavenPublishLimiter::class) {
    maxParallelUsages = 1
  }

val repositoryId: String? = System.getenv("DOKKA_MVN_CENTRAL_REPOSITORY_ID")
tasks.withType<PublishToMavenRepository>().configureEach {
  if (!repositoryId.isNullOrBlank()) usesService(mavenPublishLimiter)
}
//endregion

But in the end, as we control DOKKA_MVN_CENTRAL_REPOSITORY_ID, and we do expect that it will be set on TC when publishing to MC, we can just drop notCompatibleWithConfigurationCache configuration.

@adam-enko
Copy link
Member

Good idea! Additionally, AFAIU, this could be dropped at all when DOKKA_MVN_CENTRAL_REPOSITORY_ID is set, as there should be no issues then. Am I correct?

In theory yes, AFAIK Maven Central is the only problematic repo. But in practice I would lean towards keeping the build scripts simpler, even if it introduces a performance hit when publishing :). Is parallel publishing important for Dokka? Would it help significantly?

@whyoleg
Copy link
Collaborator

whyoleg commented Apr 15, 2024

But in practice I would lean towards keeping the build scripts simpler, even if it introduces a performance hit when publishing :). Is parallel publishing important for Dokka? Would it help significantly?

Parallel publishing is not that important, but, as I mentioned in the end, as we intend to publish to MC only from TC with DOKKA_MVN_CENTRAL_REPOSITORY_ID set, then we don't need to have additional setup in build scripts to de-parallelize publishing, as it will be just not needed at all, as it's just a hack for MC behaviour.
So by removing this, we will keep build scripts simpler :)

@IgnatBeresnev
Copy link
Member Author

@adam-enko @whyoleg thank you for the proposals!

Indeed, it seems like the only repo struggling with parallel uploads is Maven Central, so if we start using DOKKA_MVN_CENTRAL_REPOSITORY_ID, the parallelization limitations could be removed.

I'll merge this PR in to unblock me with adapting TeamCity build configurations, and will create a separate PR with the removal of config-cache disabler - there might be more questions there

@IgnatBeresnev IgnatBeresnev merged commit e22c40b into master Apr 22, 2024
12 checks passed
@IgnatBeresnev IgnatBeresnev deleted the mvn-staging-publish branch April 22, 2024 11:26
@IgnatBeresnev IgnatBeresnev modified the milestone: Dokka 2.0.0 Apr 25, 2024
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

Successfully merging this pull request may close these issues.

4 participants