Interface ModelTransformer

All Superinterfaces:
SpiService

@Experimental @Consumer @Named public interface ModelTransformer extends SpiService
Interface for model transformers that can modify Maven project models at different stages of processing.

Model transformers allow plugins and extensions to modify the POM model during the build process. Transformations can be applied at three different stages:

  1. File model - The raw model as read directly from the file
  2. Raw model - The model after inheritance has been applied
  3. Effective model - The fully processed model with all interpolation and inheritance applied

Implementations of this interface will be discovered through the Java ServiceLoader mechanism and will be called in sequence during model building.

Example usage:

 public class CustomModelTransformer implements ModelTransformer {
     public Model transformEffectiveModel(Model model) throws ModelTransformerException {
         // Add a custom property to all models
         model.getProperties().put("custom.timestamp", System.currentTimeMillis());
         return model;
     }
 }
 
Since:
4.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default org.apache.maven.api.model.Model
    transformEffectiveModel(org.apache.maven.api.model.Model model)
    Apply a transformation on the effective models.
    default org.apache.maven.api.model.Model
    transformFileModel(org.apache.maven.api.model.Model model)
    Apply a transformation on the file model.
    default org.apache.maven.api.model.Model
    transformRawModel(org.apache.maven.api.model.Model model)
    Apply a transformation on the raw models.
  • Method Details

    • transformFileModel

      @Nonnull default org.apache.maven.api.model.Model transformFileModel(@Nonnull org.apache.maven.api.model.Model model) throws ModelTransformerException
      Apply a transformation on the file model. This method will be called on each file model being loaded, just before validation.
      Parameters:
      model - the input model
      Returns:
      the transformed model, or the input model if no transformation is needed
      Throws:
      ModelTransformerException
    • transformRawModel

      @Nonnull default org.apache.maven.api.model.Model transformRawModel(@Nonnull org.apache.maven.api.model.Model model) throws ModelTransformerException
      Apply a transformation on the raw models. This method will be called on each raw model being loaded, just before validation.
      Parameters:
      model - the input model
      Returns:
      the transformed model, or the input model if no transformation is needed
      Throws:
      ModelTransformerException
    • transformEffectiveModel

      @Nonnull default org.apache.maven.api.model.Model transformEffectiveModel(@Nonnull org.apache.maven.api.model.Model model) throws ModelTransformerException
      Apply a transformation on the effective models. This method will be called on each effective model being loaded, just before validation.
      Parameters:
      model - the input model
      Returns:
      the transformed model, or the input model if no transformation is needed
      Throws:
      ModelTransformerException