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

Rework how maven project jars are calculated #475

Merged
merged 1 commit into from
Nov 13, 2020

Conversation

shs96c
Copy link
Collaborator

@shs96c shs96c commented Oct 23, 2020

Previously, we assumed that all the information required for a project
all code to be included was inside the main repository. This was put
in place largely to prevent code depending on rules_proto from
pulling in the classes from protobuf itself.

Issue #448 demonstrated that this assumption wasn't correct.

We now gather all the JavaInfos that should be included in the
artifact, as well as those of dependencies of the artifact (called
"dep_infos" in the MavenInfo provider) We then calculate the
difference of those sets to determine the input files to add to the
generated project jar.

However, this is not sufficient on its own in the case of
protocbuf. As such, we also scan for classes to exclude from the
project jar by examaning the contents of the "dep_infos" runtime jars.

Furthermore, jars that are created by aspects have no way of
expressing what their maven dependencies are. To work around this,
rules may now express MavenHintInfo which will be used to help
calculate the contents of the artifact jars and maven dependencies.

ctx,
ctx.executable._singlejar,
artifact_jars,
depset(transitive = [ji.transitive_runtime_jars for ji in info.dep_infos.to_list()]).to_list(),
Copy link
Member

Choose a reason for hiding this comment

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

This line looks like it's creating the transitive dep_info jars to be excluded from artifact_jars, where artifact_jars already excluded this same list of transitive_runtime_jars from calculate_artifact_jars. Am I misreading something or is this doing redundant work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We've excluded the same jars, but we pass in the jars to exclude to avoid including classes from them too. Quite often you find jars that contain bits of guava or the Nullable annotations by mistake. We don't want to pollute the classpath with duplicate classes. The MergeJars binary checks for this and handles it for us.

Previously, we assumed that all the information required for a project
all code to be included was inside the main repository. This was put
in place largely to prevent code depending on `rules_proto` from
pulling in the classes from protobuf itself.

Issue bazelbuild#448 demonstrated that this assumption wasn't correct.

We now gather all the JavaInfos that should be included in the
artifact, as well as those of dependencies of the artifact (called
"dep_infos" in the MavenInfo provider) We then calculate the
difference of those sets to determine the input files to add to the
generated project jar.

However, this is not sufficient on its own in the case of
protocbuf. As such, we also scan for classes to exclude from the
project jar by examaning the contents of the "dep_infos" runtime jars.

Furthermore, jars that are created by aspects have no way of
expressing what their maven dependencies are. To work around this,
rules may now express `MavenHintInfo` which will be used to help
calculate the contents of the artifact jars and maven dependencies.
@shs96c shs96c merged commit 6862295 into bazelbuild:master Nov 13, 2020
@jin jin mentioned this pull request Jan 6, 2021
4 tasks
@shs96c shs96c deleted the exclude-jars branch December 9, 2022 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants