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

Allow compile jars to strip illegal automatic module names #673

Merged
merged 2 commits into from
Mar 24, 2022

Conversation

shs96c
Copy link
Collaborator

@shs96c shs96c commented Mar 17, 2022

There are plenty of jars out there that have an Automatic-Module-Name
that isn't legal. Normally, this doesn't matter too much, but when
compiling code with a modern compiler bazel will use a module path,
and that cares a lot, causing builds to fail.

To rectify this, we can pass an additional flag when creating the
compile jar that will strip illegal automatic module names from the
generated manifests.

There are plenty of jars out there that have an `Automatic-Module-Name`
that isn't legal. Normally, this doesn't matter too much, but when
compiling code with a modern compiler bazel will use a module path,
and that cares _a lot_, causing builds to fail.

To rectify this, we can pass an additional flag when creating the
compile jar that will strip illegal automatic module names from the
generated manifests.
@cheister
Copy link
Collaborator

Do you mind adding an example error to the description when this isn't fixed? I'm curious what the problems actually look like.

manifest.getMainAttributes().put(new Attributes.Name("Created-By"), "AddJarManifestEntry");
toAdd.forEach(manifestEntry -> {
String[] manifestEntryParts = manifestEntry.split(":", 2);
manifest.getMainAttributes().put(new Attributes.Name(manifestEntryParts[0]), manifestEntryParts[1]);
});
toRemove.forEach(name -> manifest.getMainAttributes().remove(new Attributes.Name(name)));

if (!makeSafe) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not if (makeSafe) { checkAutomaticModuleName(jar, manifest); } ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@shs96c shs96c merged commit 916ee09 into bazelbuild:master Mar 24, 2022
@shs96c shs96c deleted the automatic-module-name branch March 24, 2022 14:58
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

3 participants