My immediate problem is that I use api documentation I generate in the pre-integration-test phase, and I want to use it both for the fake javadoc I create in the package phase, and for the site. I understand that the build and site lifecycle are different ones, and I could have the discipline to always run mvn pre-integration-test site
instead of mvn site
, but I want to include all knowledge about the build in the project. And the maven-surefire-reporting plugin somehow solves a similar problem.
The relevant parts of my pom.xml:
site plugin definition and creating the javadoc:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.10.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<execution>
<id>fake-javadoc</id>
<phase>post-integration-test</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
<classesDirectory>${project.build.directory}/site</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
generating the documentation (puts it directly to target/site):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>generate-apidoc</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${basedir}</workingDirectory>
<executable>tools/makeSourceDoc</executable>
</configuration>
</execution>
well, it is not actually relevant, but anyways:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
</plugin>
</plugins>
</reporting>
I tried to use the Maven Invoker Plugin:
but with mvn site
the result in both cases was:
...
[INFO] --- invoker:3.9.1:run (invoke-pre-site-pre-integration-test) @ so-79707239 ---
[INFO] No projects were selected for execution.
...
Then I tried it with the Exec Maven Plugin (with the project itself and without any code, just to test the process):
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>igb.so</groupId>
<artifactId>so-79707239</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.21.0</version>
</plugin>
<plugin>
<!-- Causes "[WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version."
if not declared here -->
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.9.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.9.1</version>
<configuration>
<!-- didn't work either
<settingsFile>../SO-79707239-javadoc-pre-site-it/src/main/resources/settings.xml</settingsFile>
<projectsDirectory>../SO-79707239-javadoc-pre-site-it</projectsDirectory>
-->
<settingsFile>src/test/resources/settings.xml</settingsFile>
<projectsDirectory>.</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<goals>
<goal>pre-integration-test</goal>
</goals>
</configuration>
<executions>
<execution>
<id>invoke-pre-site-pre-integration-test</id>
<phase>pre-site</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>exec-pre-site-pre-integration-test</id>
<phase>pre-site</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>pre-integration-test</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
and it worked:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< igb.so:so-79707239 >-------------------------
[INFO] Building so-79707239 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- invoker:3.9.1:run (invoke-pre-site-pre-integration-test) @ so-79707239 ---
[INFO] No projects were selected for execution.
[INFO]
[INFO] --- exec:3.5.1:exec (exec-pre-site-pre-integration-test) @ so-79707239 ---
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< igb.so:so-79707239 >-------------------------
[INFO] Building so-79707239 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ so-79707239 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ so-79707239 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ so-79707239 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ so-79707239 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ so-79707239 ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ so-79707239 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.917 s
[INFO] Finished at: 2025-07-20T16:22:29+02:00
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- site:3.21.0:site (default-site) @ so-79707239 ---
[INFO] Rendering site for default locale
[INFO] Configuring report plugin maven-project-info-reports-plugin:3.9.0
[INFO] Detected 15 reports for maven-project-info-reports-plugin:3.9.0: ci-management, dependencies, dependency-info, dependency-management, distribution-management, index, issue-management, licenses, mailing-lists, modules, plugin-management, plugins, scm
, summary, team
[WARNING] Unable to find a URL to the parent project. The parent menu will NOT be added.
[WARNING] No project URL defined - site links will not be relativized!
[INFO] Rendering content with org.apache.maven.skins:maven-fluido-skin:jar:2.0.0-M9 skin
[INFO] Rendering 8 report documents
[INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:3.9.0:dependencies
[INFO] Generating "Maven Coordinates" report --- maven-project-info-reports-plugin:3.9.0:dependency-info
[INFO] Generating "Dependency Management" report --- maven-project-info-reports-plugin:3.9.0:dependency-management
[INFO] Generating "About" report --- maven-project-info-reports-plugin:3.9.0:index
[INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:3.9.0:plugin-management
[INFO] Generating "Plugins" report --- maven-project-info-reports-plugin:3.9.0:plugins
[INFO] Generating "Summary" report --- maven-project-info-reports-plugin:3.9.0:summary
[INFO] Generating "Project Information" report --- maven-site-plugin:3.21.0:project-info
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.088 s
[INFO] Finished at: 2025-07-20T16:22:31+02:00
[INFO] ------------------------------------------------------------------------