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

Enforce lock constraints using shared platform #557

Merged
merged 15 commits into from
Aug 27, 2020

Conversation

dansanduleac
Copy link
Contributor

Before this PR

Creating lots of constraints into every single configuration being resolved (even though technically only once per project, after which they get inherited by all configurations).

This can lead to super large build scans (300MB for a large internal monorepo) where constraints are needlessly duplicated.

After this PR

==COMMIT_MSG==
Manage lock file constraints using a single platform, reducing the number of constraints that have to be created.

This works in a similar way to Java Platform Plugin. We can't just use that plugin directly, as it makes too many assumptions about the structure of the build where it's applied (e.g. needs its own project that isn't otherwise a java project, to hold the platform) that we can't make in GCV.
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Aug 12, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Manage lock file constraints using a single gradle "platform", reducing the number of constraints that have to be created.

Check the box to generate changelog(s)

  • Generate changelog entry

@dansanduleac dansanduleac marked this pull request as ready for review August 19, 2020 16:00
@policy-bot policy-bot bot requested a review from ferozco August 19, 2020 16:00
conf.setVisible(false);
});

ProjectDependency locksDependency =
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we create a self dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not actually "self" but pointing to a particular configuration (indirectly).
This is to pick up the locks configuration which is defined in the root project.


ProjectDependency locksDependency =
(ProjectDependency) project.getDependencies().create(project);
locksDependency.capabilities(moduleDependencyCapabilitiesHandler ->
Copy link
Contributor

Choose a reason for hiding this comment

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

is this necessary given that we already have configured the configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes - we will resolve multiple variants of the same project (root project) so if they don't have different (i.e. explicit and different) capabilities, they will conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right and you can't depend on an explicit capability just with attributes, you need to specify the capability.

If anything, we might not need to specify the attribute directly, but it's a bit more clear this way I think.

conf.setCanBeConsumed(true);
conf.setVisible(false);

// Note: don't add constraints to the ConstraintHandler, only call `create` / `platform` on it.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean here? could you explain why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was there before and mostly just meant the function accepting the ConstraintHandler doesn't call add on it, only create.
It's a bit confusing though so I'm gonna instead make up an interface that can only create, and pass that in.

@dansanduleac dansanduleac requested a review from ferozco August 26, 2020 13:56
NamedDomainObjectProvider<Configuration> rootConfiguration = project.getConfigurations()
.register(ROOT_CONFIGURATION_NAME, conf -> {
conf.setCanBeResolved(false);
conf.setCanBeConsumed(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not setting this was an oversight, now fixed

Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

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

Tested in a large internal project. Build scan is still large, but a little less so.

@dansanduleac
Copy link
Contributor Author

👍 go go go

@bulldozer-bot bulldozer-bot bot merged commit 5d28c1c into develop Aug 27, 2020
@bulldozer-bot bulldozer-bot bot deleted the ds/locks-platform branch August 27, 2020 11:59
@svc-autorelease
Copy link
Collaborator

Released 1.26.0

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

Successfully merging this pull request may close these issues.

4 participants