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 Details

    • transformFileModel

      @Nonnull default Model transformFileModel(@Nonnull 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 Model transformRawModel(@Nonnull 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 Model transformEffectiveModel(@Nonnull 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