Repository navigation
JLBP for adding module names #835
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| [JLBP-20] Give each jar a module name | ||
| -------------------------------------------------- | ||
|
|
||
| For compatibility with the Java Platform Module System (JPMS) in Java 9 and | ||
| later, every JAR you publish should have a module name, even if the library | ||
| does not itself use modules. More precisely, the JAR manifest in | ||
| META-INF/MANIFEST.MF should have an Automatic-Module-Name field such as | ||
| this one for `com.google.http-client:google-http-client`: | ||
|
|
||
| ``` | ||
| Automatic-Module-Name: com.google.api.client | ||
| ``` | ||
|
|
||
| The module name should be globally unique and composed of | ||
| dot-separated Java identifiers. It should usually be a reversed domain name such | ||
| as commonly found in Java package names. It should have the same name as the root | ||
| package of the JAR. For example, if a JAR contains `com.google.utilities.i18n` | ||
| and `com.google.utilities.strings` then `com.google.utilities` is a good | ||
| choice for module name. However if there's a second artifact that contains | ||
| `com.google.utilities.math` and `com.google.utilities.stats`, you can't choose | ||
| the name `com.google.utilities` for both modules. | ||
|
|
||
| Automatic-Module_name is similar to the OSGI Bundle-SymbolicName and should | ||
| probably have the same value as that field. | ||
|
|
||
| To add an Automatic-Module-Name field to a jar using Maven, configure the | ||
| Maven jar plugin in pom.xml like so: | ||
|
|
||
| ```xml | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <configuration> | ||
| <archive> | ||
| <manifestEntries> | ||
| <Automatic-Module-Name>com.google.api.client</Automatic-Module-Name> | ||
| </manifestEntries> | ||
| </archive> | ||
| </configuration> | ||
| </plugin> | ||
| ``` | ||
|
|
||
| To add an Automatic-Module-Name field using Gradle, add the following to | ||
| build.gradle: | ||
|
|
||
| ``` | ||
| ext.moduleName = "com.google.api.client" | ||
|
|
||
| jar { | ||
| inputs.property("moduleName", moduleName) | ||
|
|
||
| manifest { | ||
| attributes 'Automatic-Module-Name': moduleName | ||
| } | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to link to Stephen Colebourne's discussion of module naming best practices, and even recommend more strongly that we follow them (Replace "often has the same name" with "should have the same name", etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to "should" as suggested
@garrettjonesgoogle What do you think about linking to othe non-normative references?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elharo I don't have a fundamental problem with it.