apache / apache/maven-site-plugin

[MSITE-849] Unable to inject MavenProject when using `mvn site:run`

Open
#987 22 comments 0 reactions 0 assignees View on GitHub
enhancement priority:major
Dominant language
Java
Stars
55
Forks
50
Avg merge
2d 7h
Merged PRs (30d)
11

Description

**[Abel Salgado Romero](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=abel%20s.romero)** opened **[MSITE-849](https://issues.apache.org/jira/browse/MSITE-849?redirect=false)** and commented

In https://github.com/asciidoctor/asciidoctor-maven-plugin we inject a MavenProject to obtain addition configurations from the pom.xml (https://github.com/asciidoctor/asciidoctor-maven-plugin/blob/a4d86a949643ab68c124fd4c1b9b936412637d93/src/main/java/org/asciidoctor/maven/site/AsciidoctorDoxiaParser.java#L54).
This works fine with `site:site`, but when using `site:run` and accessing one of the Asciidoc generated pages we get the error below.
I saw that:
* The error occurs when trying to retrieve the instance of the MavenProject.
* Behavior is the same if I directly inject the MavenProject instead of using a provider. That is, `site:site` works, `site:run` fails because it cannot find the instance.

```java
HTTP ERROR 500

Problem accessing /hello.html. Reason:

Server Error

Caused by:

com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access Key[type=org.apache.maven.project.MavenProject, annotation=[none]] outside of a scoping block
at org.apache.maven.execution.scope.internal.MojoExecutionScopeModule.configure(MojoExecutionScopeModule.java:55) (via modules: org.eclipse.sisu.wire.WireModule -> org.apache.maven.execution.scope.internal.MojoExecutionScopeModule)
while locating org.apache.maven.project.MavenProject

1 error
at com.google.inject.internal.InternalProvisionException.toProvisionException(InternalProvisionException.java:226)
at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1053)
at org.asciidoctor.maven.site.AsciidoctorDoxiaParser.parse(AsciidoctorDoxiaParser.java:78)
at org.apache.maven.doxia.DefaultDoxia.parse(DefaultDoxia.java:65)
```

* How to reproduce:

1. clone https://github.com/asciidoctor/asciidoctor-maven-examples
2. cd asciidoc-maven-site-example
3. mvn site:run
4. Access `http://localhost:8080/hello.html`

* Env:

```
$ mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T21:00:29+02:00)
Maven home: /home/----/.sdkman/candidates/maven/current
Java version: 1.8.0_222, vendor: AdoptOpenJDK, runtime: /home/-----/.sdkman/candidates/java/8.0.222.hs-adpt/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.1.21-1-manjaro", arch: "amd64", family: "unix
```

---

**Affects:** 3.7.1, 3.8.2

**Attachments:**
- [site_site.png](https://issues.apache.org/jira/secure/attachment/12978923/site_site.png) (_150.52 kB_)

3 votes, 6 watchers

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with AsciidoctorDoxiaParser.java, especially the MavenProject lookup around the reported parse call, then reproduce with the asciidoc-maven-site-example using mvn site:run and opening /hello.html. Compare this with site:site and trace the scope behavior shown in the error. Done means site:run serves the generated page without the OutOfScopeException while site:site continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.