Skip to content

Using Maven dependency mediation#296

Merged
fvgh merged 3 commits intomasterfrom
deterministic_mvn_dependencies
Sep 11, 2018
Merged

Using Maven dependency mediation#296
fvgh merged 3 commits intomasterfrom
deterministic_mvn_dependencies

Conversation

@fvgh
Copy link
Copy Markdown
Member

@fvgh fvgh commented Sep 8, 2018

Currently Spotless uses 2 kinds of dependencies:

  • Resolved dependency list without any transitives (not fully implemented yet)
  • Single ("root") dependencies

The Provisioner interface supports "dependency lists" (currently always resolving transitives).
The previous MavenProvisioner implementation took individually each dependency as a root dependency, resolves it (and its transitives) and puts the JARs into a hash set.

There had been quite an evolution how Maven resolves transitives. Please refer to the Transitive Dependencies documentation for details.

The whole issue is NOT affecting the current formatters (due to the simple dependency structure of current formatters). However, the maven-plugin Provisioner should not interfere with the dependency resolution of Maven to avoid bugs in future evolution of Spotless.

@fvgh
Copy link
Copy Markdown
Member Author

fvgh commented Sep 8, 2018

@nedtwigg As stated above, currently the problem has no effect on the behaviour. Do you anyhow want an update of the CHANGES.md?

Sorry about the commit message. Will change it when merging.

@fvgh fvgh requested review from lutovich and nedtwigg and removed request for lutovich September 8, 2018 13:47
Copy link
Copy Markdown
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

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

I have a minor suggestion for making the tests a little easier to read, but the substance of the change looks good to me.

Set<File> files = provisioner.provisionWithDependencies("foo", "bar", "baz");

assertThat(files).containsOnly(new File("foo-1"), new File("foo-2"), new File("baz-2"));
private void resolveDependencies() throws Exception {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was a little confused about what these tests were doing at first. Maybe rename this to assertFormattingWorks. It would also be a little more robust if it didn't just run, but also asserted that the file on disk was as expected. Maybe assertFormattingWorks(String unformatted, String formatted).

Copy link
Copy Markdown
Contributor

@lutovich lutovich left a comment

Choose a reason for hiding this comment

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

Looks good to me! Made a couple tiny comments.

return mavenCoords -> mavenCoords.stream()
.flatMap(coord -> artifactResolver.resolve(coord).stream())
.collect(toSet());
return mavenCoords -> artifactResolver.resolve(mavenCoords);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe artifactResolver::resolve

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lutovich Sorry, maybe it's just to late... I lost you. Can you explain in detail?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just mean that lambda

return mavenCoords -> artifactResolver.resolve(mavenCoords);

can probably be replaced with method reference

return artifactResolver::resolve;

Then Objects.requireNonNull(artifactResolver); can also be removed because method ref will fail with NPE anyway.

@fvgh fvgh merged commit 4257fee into master Sep 11, 2018
@fvgh fvgh deleted the deterministic_mvn_dependencies branch September 11, 2018 05:02
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.

3 participants