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

Remove afterEvaluate from baseline immutables #1752

Merged
merged 4 commits into from
May 4, 2021

Conversation

CRogers
Copy link
Contributor

@CRogers CRogers commented May 4, 2021

Before this PR

Thanks to @pkoenig10's hard work, we have enabled incremental compilation of immutables classes in #1750! However, it uses afterEvaluate, which in my experience nearly always leads to pain down the road when gradle scripts get complicated and multiple afterEvaluates are run with no defined order.

After this PR

==COMMIT_MSG==
Build compiler args for com.palantir.baseline-immutables plugin lazily to avoid afterEvaluate ordering issues.
==COMMIT_MSG==

Additionally add a test.

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented May 4, 2021

Generate changelog in changelog/@unreleased

Type

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

Description

Build compiler args for com.palantir.baseline-immutables plugin lazily to avoid afterEvaluate ordering issues.

Check the box to generate changelog(s)

  • Generate changelog entry

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.

Thanks for adding at test!

import org.gradle.api.tasks.compile.JavaCompile;

public final class BaselineImmutables implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getPluginManager().withPlugin("java", unused -> {
project.afterEvaluate(proj -> {
proj.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling .stream() on a DomainObjectCollection is pretty much always a bug, as it doesn't include objects added later (and encourages people to use afterEvaluate). I wonder if we should make this an error prone check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a great idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, we do use a .stream() below correctly....

proj.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
.filter(sourceSet -> hasImmutablesProcessor(project, sourceSet))
.forEach(sourceSet -> addImmutablesIncrementalCompilerArg(project, sourceSet));
project.getExtensions().getByType(SourceSetContainer.class).configureEach(sourceSet -> {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use .matching(...) here to keep this fluent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, what would we match on here?

Copy link
Member

Choose a reason for hiding this comment

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

hasImmutablesProcessor

Copy link
Member

@pkoenig10 pkoenig10 May 4, 2021

Choose a reason for hiding this comment

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

This is what we do in some other plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this will be as lazy as it can be, as we currently check for immutables the moment the compiler args are requested, where as with .matching on the source sets would check for immutables the earliest of when each source set is created or when configureEach is called.

Also just be aware that there's a lot of really old stuff in this repo and a lot of it is a bit dodgy (but works well enough)

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to avoid fluent code because it makes the behavior less obvious to readers, especially as ordering is concerned.

Copy link
Member

Choose a reason for hiding this comment

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

Cool, make sense. Thanks for the explanation!

@bulldozer-bot bulldozer-bot bot merged commit 5afdfc8 into develop May 4, 2021
@bulldozer-bot bulldozer-bot bot deleted the callumr/less-afterevaluate branch May 4, 2021 13:08
@svc-autorelease
Copy link
Collaborator

Released 3.81.1

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.

None yet

4 participants