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

Adding JLBP-1 ("Minimize dependencies") #57

Merged

Conversation

garrettjonesgoogle
Copy link
Contributor

No description provided.

and if you require all of the transitive dependencies.
- Avoid cyclic dependencies
- E.g., gRPC depends on OpenCensus which depends on gRPC.
- Maven can detect this.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little stronger: Maven does not allow this. Build fails outright if there's a cyclic 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.

@saturnism Looking at grpc's dependencies, there is no cycle technically. It goes grpc-core -> opencensus-api -> grpc-context. Maybe you're talking about an inter-project cycle, which is actually not detectable by maven?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about this more, I think it should be a separate item - it's more subtle than just minimizing dependencies. I have pulled it offline (see internal doc).

added by just adding a single dependency to your own library,
and if you require all of the transitive dependencies.
- Avoid cyclic dependencies
- E.g., gRPC depends on OpenCensus which depends on gRPC.
Copy link
Contributor

Choose a reason for hiding this comment

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

Google style eschews Latin. That is, spell out "For example" instead of "E.g."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@garrettjonesgoogle
Copy link
Contributor Author

Addressed feedback, PTAL

@garrettjonesgoogle
Copy link
Contributor Author

cc @cpovirk

`mvn dependency:tree` (after running `mvn install -DskipTests`
to build the library) to see which transitive dependencies are
added by just adding a single dependency to your own library,
and if you require all of the transitive dependencies.

Choose a reason for hiding this comment

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

Is it worth expanding on "if you require all of the transitive dependencies"? Even if you exclude them in your project, any project that depends on yours will not see the "excludes" directives on transitive dependencies.

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 want to make sure I understand what you're saying.

Let's use the following example: say your library (C) depends on B which transitively depends on A, and in C you exclude A. It seems clear to me that if a user of C (say D) depends on C and also adds their own dependency on B, then they would pull in A (since they didn't add the exclusion of A). However, would D pull in A in the case where D only lists C as their dependency?

Choose a reason for hiding this comment

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

Right. I believe that is true, because you don't want someone else to diasable a dependency that might be needed somewhere else. <exclude> is not persisted in a published artifacts pom.xml. But now I feel like I need to double check. Let me try it out.

Copy link

@loosebazooka loosebazooka Aug 28, 2018

Choose a reason for hiding this comment

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

Sorry, I'm super wrong. I don't know why I thought this. Must have been some weird problem that I misattributed to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alrighty. I'm going to go ahead and merge as-is.

@garrettjonesgoogle garrettjonesgoogle merged commit 0614fa9 into GoogleCloudPlatform:master Aug 28, 2018

- Use the smallest scope possible. For example, auto-value doesn't
need to use compile scope, and can instead use compile-only,
since it doesn't need to appear on the classpath of consumers.
Copy link

Choose a reason for hiding this comment

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

I wouldn't recommend compile-only for auto-value and other annotations artifacts. It's caused problems for Guava users: See google/guava#2721 and various other bugs files against us.

For AutoValue specifically, I would recommend the pattern in its user guide, in which auto-value-annotations is a compile dependency and auto-value itself is an annotation processor (which apparently you can accomplish by making it provided, but that seems like not the most precise way).

I can send a PR if you'd like. Maybe you want it to include an example of when compile-only is the right thing? If so, maybe that's the servlet API case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with auto-value details, but servlets are definitely not compile-only.

Copy link

Choose a reason for hiding this comment

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

Ah, I am going off Ray's comment in an internal thread. It sounds like I can expect to hear a response from you there later :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpovirk a PR would be much appreciated! If we don't truly have any examples where we should use compile-only, then we should probably remove the mention of it.

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

5 participants