Skip to content

Community build: automatic dependency overrides #11504

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

Merged
merged 1 commit into from
Feb 23, 2021

Conversation

griggt
Copy link
Contributor

@griggt griggt commented Feb 22, 2021

A follow up to #10503.

This PR adds automatic dependency override handling to the community build using an sbt plugin.

The implementation is deliberately simple, and works thusly:

  • The sbt-community-build plugin is injected into each community build project.

  • The plugin hooks into the publishLocal task and for every published module, appends a ModuleID serialization to a tracking file.

  • The entries in the tracking file are injected as dependencyOverrides in build scope in subsequent community build projects.

Notes:

  • A fresh dependency tracking file is created for each run of the community build.

  • It was considered to apply the dependency overrides selectively at project scope.
    This was not done in this PR for two reasons:

    1. It adds considerable complexity.

    2. I ran into difficulty writing an implementation that would pass the inter-project-transitive-dep test, and have not had time to explore further.

Limitations:

Since the dependency overrides are applied en masse in build scope rather than selectively in project scope, a difficulty arises for any dependency which is published with the same organization and name but differing version, as is the case for cats-effect-2 and cats-effect-3.

This means that if some projects in the community build depend on cats-effect-2, and others depend on cats-effect-3 (causing both to be published), the automatic dependency overrides would fail for one set or the other; sbt seems to treat duplicate-keyed dependency overrides as last one wins.

Some projects may in fact depend on both, e.g. munit-cats-effect (not currently in the community build) is a multi-project build where one of its sub-projects depends on cats-effect-2 and another depends on cats-effect-3. Such a project can be handled by layering manual overrides atop the automatic dependency overrides.

Currently, no projects in the community build depend on cats-effect.

This limitation could be overcome by an implementation injecting project-scoped dependency overrides coupled with a heuristic to determine which version should be selected in the case of duplicate artifact ids.

Nevertheless I think this PR is useful in its current state.

@griggt griggt marked this pull request as ready for review February 22, 2021 22:06
@griggt griggt requested a review from smarter February 22, 2021 22:06
smarter
smarter previously approved these changes Feb 23, 2021
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'm not too worried about the cats-effect-2 vs 3 thing, once ce 3.0 is out we should get rid of ce2 from our community build and only accept projects that depend on ce3.

import sjsonnew.support.scalajson.unsafe.{ Converter, CompactPrinter, Parser }
import scala.util.{ Try, Failure }

object CommunityBuildPlugin extends AutoPlugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a quick high-level explanation of what the plugin does as a comment here?

@smarter
Copy link
Member

smarter commented Feb 23, 2021

/cc @romanowski @prolativ since they're planning changes to the community-build

Introduce a new sbt plugin: `sbt-community-build`, which tracks the
modules published during a community build run, and injects dependency
overrides to force version alignment.
@griggt griggt force-pushed the sbt-community-build branch from a8d3580 to 5175255 Compare February 23, 2021 19:49
@smarter smarter merged commit fca4e60 into scala:master Feb 23, 2021
@griggt griggt deleted the sbt-community-build branch February 23, 2021 21:59
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.

2 participants