apache / apache/maven-javadoc-plugin
[MJAVADOC-827] addStylesheet Misaligned With stylesheetFile From Dependencies
- Dominant language
- Java
- Stars
- 107
- Forks
- 116
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 16
Description
**[Mark Michaelis](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER308743)** opened **[MJAVADOC-827](https://issues.apache.org/jira/browse/MJAVADOC-827?redirect=false)** and commented
In MJAVADOC-625 support for `--add-stylesheet` has been introduced as new configuration parameter `{}{`}. The code has some issues though with several side effects compared to `` refering to a resource in a dependency.
## First Issue: Javadoc writes to src/main/javadoc
Given a snippet configuration snippet like this:
```java
from-dependeny.css
in-src-main-javadoc.css
```
If Javadoc is generated, it writes the content of `from-dependeny.css` to `{}src/main/javadoc{`}.
This is caused by the check that should ensure, that `` is only used with an existing `{}{`}.
## Second Issue: Additional Stylesheets Not Read From Dependencies
Unlike `{}{`}, files given in `` are not taken from dependencies which was expected by us.
Thus, the assumption would be, that this should work (now using the default stylesheet, not overriding `{}{`}):
```java
additional-from-dependency.css
```
This does won't work, because the corresponding code only respects the Javadoc-folder, thus `src/main/javadoc` and not any other – including resources provided by dependencies.
## The Cause
The cause is located around these lines:
* [maven-javadoc-plugin/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java at maven-javadoc-plugin-3.11.2 · apache/maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin/blob/maven-javadoc-plugin-3.11.2/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java#L2762-L2820)
First, `getAddStylesheet` does not get the `javadocOutputDirectory` as the parameter suggests, but instead `{}getJavadocDirectory(){`}.
**First Issue:** This causes the subsequent check for the main stylesheet file to exist to write to `src/main/javadoc` (due to the internal call to `{}getResource(){`}).
**Second Issue:** Unlike `{}getStylesheetFile(){`}, `getAddStylesheet() `does not invoke `getResource()` if a stylesheet file cannot be found. Instead, it just fails with an exception.
**Kind of third issue (design scope):** While `getStylesheetFile()` just complains, that files do not exist (but does not fail), `getAddStylesheet()` always fails, when a file does not exist. When fixing this issue, it needs to be decided, if this contract should be kept as is, or if we just forward to `getResource()` as final fallback without raising an extra exception.
Regarding the very similar approach, both behaviors should be aligned here, so that I would vote for skipping the exception and leave it at a warning instead.
## Workaround
There are several workarounds, like first unpacking resources via dependency plugin. I preferred using `` and subsequent `` to bypass the invalid check in `{}getAddStylesheet(){`}:
```java
com.mycompany
common-javadoc-resources
${project.version}
--add-stylesheet
additional-from-dependency.css
```
---
**Affects:** 3.3.0, 3.11.2
**Issue Links:**
- [MJAVADOC-625](https://issues.apache.org/jira/browse/MJAVADOC-625) Support for multiple stylesheets
1 votes, 2 watchers
Contributor guide
No contributing guide indexed for this repository
Research direction
Read AbstractJavadocMojo.java around lines 2762–2820, starting with getAddStylesheet(), getStylesheetFile(), and getResource(). Reproduce both dependency-resource configurations from the issue and compare their resolution and missing-file behavior; done means addStylesheet handling is aligned with stylesheetFile without writing the dependency resource to src/main/javadoc.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100