-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[MJAVADOC-769] fix for transitive filename based modules #227
Conversation
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.
Should we have some of assertions on generate javadocs?
Does simply success build is enough?
.../projects/MJAVADOC-769/src/main/java/mavenbugs/mjavadoc769/InternalImportBindingBuilder.java
Show resolved
Hide resolved
src/it/projects/MJAVADOC-769/src/test/java/mavenbugs/mjavadoc769/RightTest.java
Show resolved
Hide resolved
<id>javadoc-jar</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> |
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.
We build test-jar with tests classes - but java doc is executed only for main java code.
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.
that is irrelevant. The tests are only executed to illustrate why the scopes in the pom make sense. The dependency scopes in the pom is what exhibits the problem that this patch fixes.
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.
Please consider to use goals:
- javadoc-no-fork and test-javadoc-no-fork
we not need jars with javadocs
When a project depends on an artifact with a manifest entry for Automatic-Module-Name which in turn depends on an artifact that uses the filename to determine the module name, it will move the former onto the module path and patch the latter into the main artifact. However, now the direct dependency on the module path can no longer access the classes that have been patched only into the main module and javadoc generation fails. As the JDK only differentiates between modules with a module descriptor and "everything else" (modules with an automatic module entry in the manifest and modules with file name based names), the javadoc plugin should do the same. This patch changes the treatment of dependencies with an Automatic-Module-Name to match dependencies that use a filename based module name. The plugin now patches all of those dependencies into the main module and the build succeeds. Includes an integration test.
fd7a367
to
2f133a9
Compare
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>test-jar</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> |
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.
This execution should be before javadoc - it can have impact on test
I did a test, in test project execute
so I assume that existing project jar with Of course your fix resolve such issue disclosure - I'm starting a journey with JPMS 😄 |
thanks for checking this. Do you have the exact error that you saw? Is it an open source project that I can check out? |
I will hold off merging until I understand what fails here. |
I am not sure that the behavior that you are observing is related to this PR. With the current release (3.5.0): When running "clean javadoc:javadoc", the javadoc plugin will consider your project to not use modules (the whole "automatic module name" thing is broken/iffy. JPMS itself only considers two different things: modules (which have a module-info.java) and "everything else". Maven tries to differentiate between modules, "things that have an automatic module name set" and "things that use filename based module names" which is IMHO wrong). Anyway, in my project, if I use "clean javadoc:javadoc", this is what gets executed:
however, when I run "clean package javadoc:javadoc", the javadoc plugin will see the jar which now contains a META-INF/MANIFEST.MF with an automatic module name and consider this project to be modularized (which is IMHO wrong but this is for another day to discuss) and executes
In your case, the second one succeeds and the first one fails. What the patch does is that only "real" modules (the ones with a module descriptor) end up on the module path and everything else ends up being patched. e.g. for my project, this is how javadoc is called without the patch:
and with the patch:
which may or may not make a difference in your case. But I am fairly certain that the failure that you observe with If you run the javadoc process with the |
This is the slightly longer (and a bit more winded) explanation of what that patch does: consider a project that spits out a module. This can be a defined module or an automatic module; it does not actually matter. What is important is that the maven tool chain considers it something where it will use the module path. let's consider this dependency graph:
To run code that uses these three modules, it needs to do When the maven toolchain is trying to set up javadoc generation, it will inspect all three modules and come to the following conclusion:
(this is buried deep in the plexus-java component) Now, the javadoc plugin sees this and creates module and classpath:
because it treats the So, everything cool? No. What happens now is that a class in the main module (
so the right fix is one of two things:
And that is what this patch does: It removes the differentiation between manifest and filename based dependencies. A more complete fix would do this:
E.g.
So the result is
Or in the case above, the chain If guice ever wises up and provides a module descriptor, it would be this scenario: Which would force guice onto the module path and its dependency (javax.inject) as well. That works as well as patching both. What does not work is move one of them onto the module path and patch the other one into the main module. I would implement that, except that AbstractJavadocMojo.java is a brittle 6,100 lines (!) abomination littered with special cases, exceptions and dependencies on other components of unclear function. Also most mojos in the plugin share functionality here, all the way to the aggregation jar target. I did not dare to touch this and so I did the minimal invasive patch. No, seriously, this thing needs to be refactored before any serious work can be done. Or better yet, thrown away and start over (maven-javadoc-next-plugin anyone?) |
When a project depends on an artifact with a manifest entry for
Automatic-Module-Name which in turn depends on an artifact that uses the
filename to determine the module name, it will move the former onto the
module path and patch the latter into the main artifact. However, now
the direct dependency on the module path can no longer access the
classes that have been patched only into the main module and javadoc
generation fails.
As the JDK only differentiates between modules with a module descriptor
and "everything else" (modules with an automatic module entry in the
manifest and modules with file name based names), the javadoc plugin
should do the same.
This patch changes the treatment of dependencies with an
Automatic-Module-Name to match dependencies that use a filename based
module name. The plugin now patches all of those dependencies into the
main module and the build succeeds.
Includes an integration test.
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MJAVADOC-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
MJAVADOC-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verify -Prun-its
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.