Class GenerateBomMojo

java.lang.Object
network.ike.plugin.GenerateBomMojo
All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo

@Mojo(name="generate-bom", defaultPhase="generate-resources", projectRequired=true) public class GenerateBomMojo extends Object implements org.apache.maven.api.plugin.Mojo
Generate a Bill of Materials POM from another module's dependency management.

Why this goal exists

Maven 4's consumer POM resolves property references in <dependencies> but not in <dependencyManagement>. When an external project imports a BOM via <scope>import</scope>, it receives the consumer POM — so any ${…} expressions in managed dependency versions arrive unresolved and the build fails. flatten-maven-plugin, the Maven 3 solution for this class of problem, has not been updated for the Maven 4 model changes.

This goal works around the limitation by reading the <dependencyManagement> entries from a source module (default: ike-parent) in the reactor, resolving every property reference to a literal value, and writing a standalone BOM POM. The generated POM replaces the stub POM for install/deploy, so external consumers get a fully populated BOM without any manual maintenance. The generated POM uses the 4.0.0 model version for maximum consumer compatibility.

Usage

Bind this goal to a POM-packaged stub module in the reactor, ordered after the source module and the plugin module:

<plugin>
  <groupId>network.ike</groupId>
  <artifactId>ike-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>generate-bom</id>
      <goals><goal>generate-bom</goal></goals>
    </execution>
  </executions>
</plugin>
  • Constructor Details

    • GenerateBomMojo

      public GenerateBomMojo()
      Creates this goal instance.
  • Method Details

    • getLog

      protected org.apache.maven.api.plugin.Log getLog()
      Access the Maven logger.
      Returns:
      the logger
    • execute

      public void execute() throws org.apache.maven.api.plugin.MojoException
      Specified by:
      execute in interface org.apache.maven.api.plugin.Mojo
      Throws:
      org.apache.maven.api.plugin.MojoException
    • buildBomXml

      public static String buildBomXml(String groupId, String artifactId, String version, String name, String description, String url, List<BomEntry> entries)
      Build a complete BOM POM XML string from the given project coordinates and dependency entries.

      This is a pure function with no Maven or I/O dependencies, suitable for direct unit testing.

      Parameters:
      groupId - project group ID
      artifactId - project artifact ID
      version - project version
      name - project display name (XML-escaped internally)
      description - project description (may be null)
      url - project URL (may be null)
      entries - managed dependency entries
      Returns:
      well-formed POM XML
    • escapeXml

      public static String escapeXml(String text)
      Escape XML special characters in text content.
      Parameters:
      text - input text (may be null)
      Returns:
      escaped text, or empty string if null