From 1208bb7d11d015fc3c99feee007616f39e4e894c Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 10:04:20 -0400 Subject: [PATCH 1/7] JLBP for adding module names --- library-best-practices/JLBP-20.md | 48 +++++++++++++++++++++++++++++++ library-best-practices/README.md | 1 + 2 files changed, 49 insertions(+) create mode 100644 library-best-practices/JLBP-20.md diff --git a/library-best-practices/JLBP-20.md b/library-best-practices/JLBP-20.md new file mode 100644 index 0000000000..61e44b1535 --- /dev/null +++ b/library-best-practices/JLBP-20.md @@ -0,0 +1,48 @@ +[JLBP-19] 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 usually be a reversed domain name such as commonly +found in Java package names. It often has the same name as one of the packages +in the JAR, though of course JARs frequently contain more than one package. + +To add an Automatic-Module-Name field to a jar using Maven configure the +Maven jar plugin in pom.xml like so: + +```xml + + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + com.google.api.client + + + + +``` + +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 + } +} +``` diff --git a/library-best-practices/README.md b/library-best-practices/README.md index 5375e37115..984efca257 100644 --- a/library-best-practices/README.md +++ b/library-best-practices/README.md @@ -38,3 +38,4 @@ or significantly changed before the set is classified as Beta. - [JLBP-17](JLBP-17.md): Coordinate rollout of breaking changes - [JLBP-18](JLBP-18.md): Only shade dependencies as a last resort - [JLBP-19](JLBP-19.md): Place each package in only one module +- [JLBP-20](JLBP-19.md): Give each jar a module name From b8160cc5b9438b9edf680bb198d21fc0e6ae3f55 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 10:04:51 -0400 Subject: [PATCH 2/7] JLBP for adding module names --- library-best-practices/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library-best-practices/README.md b/library-best-practices/README.md index 984efca257..b8de8f4c2e 100644 --- a/library-best-practices/README.md +++ b/library-best-practices/README.md @@ -38,4 +38,4 @@ or significantly changed before the set is classified as Beta. - [JLBP-17](JLBP-17.md): Coordinate rollout of breaking changes - [JLBP-18](JLBP-18.md): Only shade dependencies as a last resort - [JLBP-19](JLBP-19.md): Place each package in only one module -- [JLBP-20](JLBP-19.md): Give each jar a module name +- [JLBP-20](JLBP-20.md): Give each jar a module name From d610f66053682b40554ba2548b435d45e7db9408 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 10:17:55 -0400 Subject: [PATCH 3/7] more examples --- library-best-practices/JLBP-20.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/library-best-practices/JLBP-20.md b/library-best-practices/JLBP-20.md index 61e44b1535..43835e1950 100644 --- a/library-best-practices/JLBP-20.md +++ b/library-best-practices/JLBP-20.md @@ -11,9 +11,17 @@ this one for `com.google.http-client:google-http-client`: Automatic-Module-Name: com.google.api.client ``` -The module name should usually be a reversed domain name such as commonly -found in Java package names. It often has the same name as one of the packages -in the JAR, though of course JARs frequently contain more than one package. +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 often has 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 use +`com.google.utilities` for both. + +This 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: From aa240732f381c5bfc9fe0d19544916f85b4ce06a Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 10:24:22 -0400 Subject: [PATCH 4/7] more examples --- library-best-practices/JLBP-20.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library-best-practices/JLBP-20.md b/library-best-practices/JLBP-20.md index 43835e1950..0634061f56 100644 --- a/library-best-practices/JLBP-20.md +++ b/library-best-practices/JLBP-20.md @@ -17,8 +17,8 @@ as commonly found in Java package names. It often has 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 use -`com.google.utilities` for both. +`com.google.utilities.math` and `com.google.utilities.stats`, you can't choose +the name `com.google.utilities` for both modules. This is similar to the OSGI Bundle-SymbolicName and should probably have the same value as that field. From 4e3d3632e79bfb32bfc27f76206358ec28ba5aa9 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 10:24:46 -0400 Subject: [PATCH 5/7] more examples --- library-best-practices/JLBP-20.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library-best-practices/JLBP-20.md b/library-best-practices/JLBP-20.md index 0634061f56..ad311dbd18 100644 --- a/library-best-practices/JLBP-20.md +++ b/library-best-practices/JLBP-20.md @@ -1,4 +1,4 @@ -[JLBP-19] Give each jar a module name +[JLBP-20] Give each jar a module name -------------------------------------------------- For compatibility with the Java Platform Module System (JPMS) in Java 9 and From 9e780c205b9859bac55173a712fa9128d776ad84 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 11:09:16 -0400 Subject: [PATCH 6/7] don't need manifestFile --- library-best-practices/JLBP-20.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/library-best-practices/JLBP-20.md b/library-best-practices/JLBP-20.md index ad311dbd18..e2fbfee9c1 100644 --- a/library-best-practices/JLBP-20.md +++ b/library-best-practices/JLBP-20.md @@ -30,13 +30,12 @@ Maven jar plugin in pom.xml like so: maven-jar-plugin - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - com.google.api.client - - - + + + com.google.api.client + + + ``` From 6cf836f4d37481e4a8c12a54e363e6adc74a5874 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 8 Aug 2019 13:06:51 -0400 Subject: [PATCH 7/7] should --- library-best-practices/JLBP-20.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library-best-practices/JLBP-20.md b/library-best-practices/JLBP-20.md index e2fbfee9c1..38d9877ece 100644 --- a/library-best-practices/JLBP-20.md +++ b/library-best-practices/JLBP-20.md @@ -13,17 +13,17 @@ 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 often has the same name as the root +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. -This is similar to the OSGI Bundle-SymbolicName and should probably have the -same value as that field. +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 +To add an Automatic-Module-Name field to a jar using Maven, configure the Maven jar plugin in pom.xml like so: ```xml