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

New baseline-class-uniqueness.lock file allows incremental adoption #1145

Merged
merged 19 commits into from
Jan 7, 2020

Conversation

iamdanfox
Copy link
Contributor

@iamdanfox iamdanfox commented Jan 7, 2020

Before this PR

It's pretty hard to roll out the baseline-class-uniqueness plugin because it currently is quite an "all or nothing" thing - either you're 100% compliant or else it fails. We haven't really invested in this up until now, because not that much seems to go wrong.

HOWEVER - a recent c-j-r dependency upgrade brought in new 'jakarta' jars, which are renamed versions of javax ones (e.g. javax.ws.rs:javax.ws.rs-api:2.1 and jakarta.ws.rs:jakarta.ws.rs-api:2.1.6 are pretty much the same thing). People are now starting to get confusing runtime errors from these. Internally, I've got a plugin to automatically fix the problem (gradle-jakarta-renames), but in order to roll that out, I want to ensure people can code-review the changes that it causes.

After this PR

==COMMIT_MSG==
Users can now apply plugin: 'com.palantir.baseline-class-uniqueness' even if they are not yet fully compliant, as the plugin will now just record conflicts in a lock-file. This makes it easier to incrementally improve projects, rather than asking people to fix things in a big-bang way.
==COMMIT_MSG==

@raiju for SA who cared about this stuff before

before merging

  • tests
  • decide if we want to delete the old stuff too?

Possible downsides?

  • There is lots of room to make the class uniqueness analyzing more efficient (it's currently pretty naiive)... If 100 projects all run baseline-class-uniqueness and depend on one jar, I think that jar will get unpacked and analyzed 100 times.
  • more lock files might confuse people

@changelog-app
Copy link

changelog-app bot commented Jan 7, 2020

Generate changelog in changelog/@unreleased

Type

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

Description

The com.palantir.baseline-class-uniqueness plugin now records conflicts in a baseline-class-uniqueness.lock file. This should be checked-in to git and makes it easier to incrementally improve projects, rather than requiring a big-bang migration.

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from ferozco January 7, 2020 15:54
if (!onDisk.equals(expected)) {
throw new GradleException(lockFile
+ " is out of date, please run `./gradlew "
+ "checkClassUniquenessLock --write-locks` to update this file");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may want to provide a different message if new duplicates appear vs when problems are fixed, or mention here that it's dangerous to have duplicate classes on the classpath and explain why it's worth spending time to fix.
Otherwise I think folks will see "run X to update locks" and they'll ./X.

@iamdanfox iamdanfox force-pushed the lockable-class-uniqueness branch from bd1da4b to f34a748 Compare January 7, 2020 17:34
+ "cause different behaviour depending on classpath ordering.\n"
+ "# Run ./gradlew checkClassUniqueness --write-locks to update this file\n\n";

// not marking this as an Input, because we want to re-run if the *contents* of a configuration changes
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't the contents only change if a dependency on the configuration changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Configurations are not Serializable, so I can't just mark a list of them as an @Input.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can take the configuration as an input by annotating it with @classpath

Copy link
Contributor Author

@iamdanfox iamdanfox Jan 7, 2020

Choose a reason for hiding this comment

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

I think that @classpath annotation would work if I had just a single configuration, but in order to preserve the ability to analyze multiple configurations, I don't have just one single configuration here but a bunch of them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of storing a set of configurations could you create a single configuration which extends from all of the provided configurations

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 dunno, it seems that has a slight risk of false positives... e.g. if we're analyzing two configurations foo and bar and we move a jar from foo -> bar. In the big clobbered configuration there would be no change, but actually I would expect the lockfile to change.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok no big deal

@iamdanfox
Copy link
Contributor Author

FWIW I've been iterating on this with share-link-service and it nicely highlights all the jakarta problems, then when I apply gradle-jakarta-renames they all go away.

@carterkozak
Copy link
Contributor

Fantastic!

This was referenced Jan 8, 2020
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.

5 participants