You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now, that Dagger runs with JDK 9 (as issue #880 is resolved), it might be time to look forward to JPMS compatibility.
In a first step I'd suggest to add a Automatic-Module-Name entry to the jar manifest. This way other libraries depending on Dagger can be published to Maven Central or other repositories. Without it, the automatic module name would be derived from the Dagger .jar file and as such is pretty unreliable.
This proposed change doesn't affect any code and will simply make a name reservation until an actual module-info.java will be added eventually. More info can be found in this blog post.
Reacted by Dunemaster, Jay Newstrom, BeshEater and Grzegorz Nowak
To get this issue going, since it can be solved by a single line of configuration:
I don't know how to configure bazel builds, but apparently there is this deploy_manifest_lines argument in the java_binary rule that should allow you to add entries to the MANIFEST.MF.
However, this argument doesn't exist for the java_library rule, which wouldn't make too much sense. Probably just bad documentation?
Currently the build uses java_library rules which don't support MANIFEST.MF additions (see: bazelbuild/bazel#4197). According to linked issue, the output of java_library is only intermediary and should not be used for deployment (java_binary and java_test should be used for such purpose):
Bazel considers only java_binary or java_test as rules that output something for deployment. The other rules should be used as intermediary and the user, in theory, should not depend on the jars created (e.g. by java_library) or implementation details.
Also java_binary's deploy_manifest_lines works only for a name_deploy.jar which is an uber-jar containing all the dependencies. Regular name.jar is not affected as mentioned in documentation and bazelbuild/bazel#2009
To summarize bazel doesn't support custom MANIFEST.MF attributes for main java artifacts and the feature request is open since 2017.
As a workaround we could use jar x command from JDK to extract existing MANIFEST.MF, append required lines and finally update the artifact using jar u command. All this could be added to execute-deploy.sh script.
@ronshapiro FYI currently without the Automatic-Module-Name the name of the module is derived from the file name so for maven artifact dagger-2.26.jar it's dagger:
Because of that maven build outputs following message:
[WARNING] **** (...)
[WARNING] * Required filename-based automodules detected: [dagger-2.26.jar]. Please don't publish this project to a public artifact repository! *
[WARNING] **** (...)
Seems like this autogenerated module name (dagger) could be used for manifest entry and in the future, in the module-info.java. @overheadhunter provided one article about naming in JPMS.
Below you can find some more (written by @jodastephen)
As per the blog, the module name for each jar file is generally the root package name of the jar file. At a quick glance that would appear to be dagger. (The artifact name is not the one to use, so it isn't com.google.dagger as that is not a package name).
Could any of the decision-making contributors suggest / choose a solution?
From my perspective we have 3 options (sorted by the increasing effort required):
Add a pre-maven-deploy process which modifies bazel generated jars by appending required lines in the MANIFEST.MF. As mentioned above JDK jar command has built-in support for this. (involves execute-deploy.sh)
Seems like (2) won't be accepted in bazel, (3) is stalled and adding the functionality in bazel is non trivial (core contributors didn't figure out yet how to implement it). Also (3) will require major changes in the dagger build infrastructure (simple additions in BUILD files won't suffice)
# Concatenate similar files in META-INF that allow it.
mergeMetaInfFiles=(services/.* {merge_meta_inf_files})
for metaInfPattern in ${{mergeMetaInfFiles[@]}}; do
for file in $(find META-INF -regex "META-INF/$metaInfPattern\\(~[0-9]*\\)?"); do
original=$(echo $file | sed s/"~[0-9]*$"//)
if [[ "$file" != "$original" ]]; then
cat $file >> $original
rm $file
fi
done
done
Again we have few options here:
Extend jarjar to properly support manifest merging and customizations. Update bazel build rule in the process. Not sure which one though (google's, pants' or shevek's. (The last one seems the most updated)
Update jarjar_library rule to support additional attribute - manifest file which will be merged with the ones extracted from input jars.
BTW @netdpb I guess I understand now how you came up with this idea :)
Yeah, I think we still need to decide on module names. Based off #1079 (comment), it seems like dagger is the correct module name for the com.google.dagger:dagger artifact.
Going through each of our artifacts, I've listed the likely java module names in the table below. If these seem reasonable, I can try to add these to the META-INF as suggested in #1079 (comment)
Just something to bear in mind is that you can't have two modules with the same name loaded at the same time. The list above suggests you have split packages, where the same package appears in two different jar files. If that is the case, then you can't really modularise as is.
(The exception to that rule is if the user is expected to choose one of the artifacts, eg one of"dagger-android-jarimpl", "dagger-android-legacy" or "dagger-android-processor".)
Right, but the most critical is com.google.dagger:dagger, as that is the primary interface to other modules. Once that has a stable name, people can start publishing components referring to it.
@rovarga it's not that simple. Once a project claims a module name, it's responsible for its contents and compatibility. If dagger is too eager, it may cause split package problem which will be hard to solve. Most of the projects from pre-JPMS era will require some API package refactoring to solve this, meaning major version release.
@metteo True, but that needs analysis of whether com.google.dagger:dagger split packages against all the others. If it does not, it is fine.
Nothing changes in the class/modulepath world, so it should be pretty safe. If there is functionality present which should be in a separate module, dagger.jar can deal with it in JPMS through a 'requires transitive dagger.this.should.have.been.elserwhere;'.
Took another look at this and I think what might make sense is for us to add the automatic name entry in just the main dagger artifact to claim the module name dagger. I think this would solve most of the use cases without committing us too much in terms of module structure where we might need to evaluate our situation with respect to split packages.
I'll work on adding this entry assuming that sounds reasonable.
Activity
ronshapiro commentedon Mar 5, 2018
This sounds fine to me. I presume that we'll probably want the module names to match the maven artifact names?
com.google.daggercom.google.dagger.compilercom.google.dagger.producerscom.google.dagger.androidcom.google.dagger.android.supportetc.
@netdpb WDYT?
JakeWharton commentedon Mar 5, 2018
overheadhunter commentedon Jul 26, 2019
To get this issue going, since it can be solved by a single line of configuration:
I don't know how to configure bazel builds, but apparently there is this
deploy_manifest_linesargument in the java_binary rule that should allow you to add entries to theMANIFEST.MF.However, this argument doesn't exist for the java_library rule, which wouldn't make too much sense. Probably just bad documentation?
metteo commentedon Mar 1, 2020
Currently the build uses
java_libraryrules which don't supportMANIFEST.MFadditions (see: bazelbuild/bazel#4197). According to linked issue, the output ofjava_libraryis only intermediary and should not be used for deployment (java_binaryandjava_testshould be used for such purpose):@iirina wrote:
Also
java_binary'sdeploy_manifest_linesworks only for aname_deploy.jarwhich is an uber-jar containing all the dependencies. Regularname.jaris not affected as mentioned in documentation and bazelbuild/bazel#2009To summarize bazel doesn't support custom
MANIFEST.MFattributes for main java artifacts and the feature request is open since 2017.As a workaround we could use
jar xcommand from JDK to extract existingMANIFEST.MF, append required lines and finally update the artifact usingjar ucommand. All this could be added toexecute-deploy.shscript.metteo commentedon Mar 1, 2020
@ronshapiro FYI currently without the
Automatic-Module-Namethe name of the module is derived from the file name so for maven artifactdagger-2.26.jarit'sdagger:Because of that maven build outputs following message:
Seems like this autogenerated module name (
dagger) could be used for manifest entry and in the future, in themodule-info.java. @overheadhunter provided one article about naming in JPMS.Below you can find some more (written by @jodastephen)
Java SE 9 - JPMS module naming
Java SE 9 - JPMS modules are not artifacts
jodastephen commentedon Mar 2, 2020
As per the blog, the module name for each jar file is generally the root package name of the jar file. At a quick glance that would appear to be
dagger. (The artifact name is not the one to use, so it isn'tcom.google.daggeras that is not a package name).metteo commentedon Mar 9, 2020
Could any of the decision-making contributors suggest / choose a solution?
From my perspective we have 3 options (sorted by the increasing effort required):
bazelgenerated jars by appending required lines in theMANIFEST.MF. As mentioned above JDKjarcommand has built-in support for this. (involvesexecute-deploy.sh)MANIFEST.MFcustomizations injava_libraryintermediary output and use it to includeAutomatic-Module-Name. (java_library: Support manifest manipulation bazelbuild/bazel#4197 - closed in 2017)MANIFEST.MFcustomizations injava_binarymain artifact (java_binary: No way to provide dynamic manifest file content bazelbuild/bazel#2009 - inactive since 2017)3.1. Switch
daggerbuild to usejava_binary(involvesBUILDand.shfiles)Seems like (2) won't be accepted in bazel, (3) is stalled and adding the functionality in bazel is non trivial (core contributors didn't figure out yet how to implement it). Also (3) will require major changes in the
daggerbuild infrastructure (simple additions inBUILDfiles won't suffice)netdpb commentedon Mar 9, 2020
Dagger already uses jarjar to create the Maven artifact. We can use or modify that to append to the MANIFEST.MF file.
metteo commentedon Mar 9, 2020
At the moment
jarjar_libraryis used for generation ofshaded_grpc_server_processorandshaded_android_processorhere.However the one that we are interested in is deployed directly:
Even if we would process it with jarjar it wouldn't help because it doesn't support manifest merging. Instead
jarjar_libraryrule uses inlined bash script to do that:Again we have few options here:
jarjarto properly support manifest merging and customizations. Update bazel build rule in the process. Not sure which one though (google's, pants' or shevek's. (The last one seems the most updated)jarjar_libraryrule to support additional attribute - manifest file which will be merged with the ones extracted from input jars.BTW @netdpb I guess I understand now how you came up with this idea :)
bcorso commentedon Mar 9, 2020
Short-term, I think we'll want to go with option 2.
netdpb commentedon Mar 10, 2020
rovarga commentedon Oct 21, 2020
Any progress on this? :-)
Even if not on the implementation side, has the module name been agreed to be 'dagger'?
bcorso commentedon Oct 21, 2020
Yeah, I think we still need to decide on module names. Based off #1079 (comment), it seems like
daggeris the correct module name for thecom.google.dagger:daggerartifact.Going through each of our artifacts, I've listed the likely java module names in the table below. If these seem reasonable, I can try to add these to the META-INF as suggested in #1079 (comment)
jodastephen commentedon Oct 31, 2020
Just something to bear in mind is that you can't have two modules with the same name loaded at the same time. The list above suggests you have split packages, where the same package appears in two different jar files. If that is the case, then you can't really modularise as is.
(The exception to that rule is if the user is expected to choose one of the artifacts, eg one of"dagger-android-jarimpl", "dagger-android-legacy" or "dagger-android-processor".)
rovarga commentedon Oct 31, 2020
Right, but the most critical is com.google.dagger:dagger, as that is the primary interface to other modules. Once that has a stable name, people can start publishing components referring to it.
metteo commentedon Oct 31, 2020
@rovarga it's not that simple. Once a project claims a module name, it's responsible for its contents and compatibility. If dagger is too eager, it may cause split package problem which will be hard to solve. Most of the projects from pre-JPMS era will require some API package refactoring to solve this, meaning major version release.
rovarga commentedon Nov 1, 2020
@metteo True, but that needs analysis of whether com.google.dagger:dagger split packages against all the others. If it does not, it is fine.
Nothing changes in the class/modulepath world, so it should be pretty safe. If there is functionality present which should be in a separate module, dagger.jar can deal with it in JPMS through a 'requires transitive dagger.this.should.have.been.elserwhere;'.
rjbaucells commentedon Apr 28, 2021
Any progress on this?
Chang-Eric commentedon May 6, 2021
Took another look at this and I think what might make sense is for us to add the automatic name entry in just the main dagger artifact to claim the module name
dagger. I think this would solve most of the use cases without committing us too much in terms of module structure where we might need to evaluate our situation with respect to split packages.I'll work on adding this entry assuming that sounds reasonable.
Add an automatic module name entry into the MANIFEST.MF to support JPMS.
Add an automatic module name entry into the MANIFEST.MF to support JPMS.