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

create GradleTaskConfigurationAvoidance error prone check #2373

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

rzpt
Copy link
Contributor

@rzpt rzpt commented Sep 7, 2022

Before this PR

There is no error prone check to prevent usages of these gradle apis which can make gradle commands unnecessarily slow. Some of the apis are also very likely to be mistakenly used.

After this PR

==COMMIT_MSG==
Create GradleTaskConfigurationAvoidance error prone check to prevent
eager task creation.
==COMMIT_MSG==

Possible downsides?

None.

Do not use gradle apis that eagerly create tasks.
@changelog-app
Copy link

changelog-app bot commented Sep 7, 2022

Generate changelog in changelog/@unreleased

Type

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

Description

Create GradleTaskConfigurationAvoidance error prone check to prevent
eager task creation.

Check the box to generate changelog(s)

  • Generate changelog entry


@AutoService(BugChecker.class)
@BugPattern(
link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks",
Copy link
Contributor

Choose a reason for hiding this comment

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

drive-by: unless i'm missing something the README also needs to be updated with the addition of this check

link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks",
linkType = BugPattern.LinkType.CUSTOM,
severity = SeverityLevel.ERROR,
summary = "Forbid gradle apis that eagerly create tasks.")
Copy link
Contributor

Choose a reason for hiding this comment

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

can this have more detail here on what the user should do instead?

@BugPattern(
link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks",
linkType = BugPattern.LinkType.CUSTOM,
severity = SeverityLevel.ERROR,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we start this at a lower severity level that shows just warnings before making this fail builds? We have to give projects some time between getting a new baseline version that shows warnings and making those warnings fail the build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Does anyone look at warnings though? Most projects that are affected are gradle plugins, which are probably not actively developed.

linkType = BugPattern.LinkType.CUSTOM,
severity = SeverityLevel.ERROR,
summary = "Forbid gradle apis that eagerly create tasks. Learn more at"
+ " https://docs.gradle.org/current/userguide/task_configuration_avoidance.html")
Copy link
Contributor

Choose a reason for hiding this comment

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

is there more specific guidance devs should follow how to fix any of these warnings that will be thrown? Is https://docs.gradle.org/current/userguide/task_configuration_avoidance.html#sec:task_configuration_avoidance_pitfalls the best guidance that's out there and changing from eager task creation to lazy task creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As someone who doesn't really work on gradle plugins, I don't know the answer to this.

+ " https://docs.gradle.org/current/userguide/task_configuration_avoidance.html")
@SuppressWarnings("deprecation")
public final class GradleTaskConfigurationAvoidance extends BugChecker
implements BugChecker.MethodInvocationTreeMatcher {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this also work on .gradle files written in Groovy? The tests are only in Java, so I'm not sure if this would run on .gradle files. Or is this only meant to run on gradle plugins written in Java?

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 believe it does not because error prone only runs on java.

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.

None yet

4 participants