validationmavenmaven-pluginflexmojos

Building custom Maven ModelValidators


I use the flexmojos plugin quite a lot and am trying to help people on the flexmojos mailinglist as good as I can.

While helping, I could see that a hand full of problems allway reoccur and usually allways have the same solution.

My idea now was to add some sort of validation code to flexmojos in order to make it easier for people to find out what's going wrong. While looking through the Maven code I enountered the ModelValidators (mainly because I was trying to find a way to get rid of those anoying scope warnings). I thougt it would be a good Idea to create a validator that implements ModelValidator and to include that in the plugin.

Unfortunately I couldn't find a documented way to actually provide custom validators. Could someone here please guide me to how this is done or stop me from seaching any longer if the DefaultModelValidator is the only one that Maven supports.

Chris


Solution

  • Ok ... I finally figgured out a solution to my problem. Here goes:

    In general Maven doesn't support what I want. Fortunately there is a way to do it. As I am reconfiguring Maven, I have to create a component with the role ModelValidator. If I then place the jar containing this component in my MAVEN_HOME/lib/ext directory, it overrides the weaving and my ModelValidator is used instead of the default one.

    @Component( role = ModelValidator.class )
    public class FMDefaultModelValidator extends DefaultModelValidator {
        @Override
        public void validateEffectiveModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
            //super.validateEffectiveModel(model, request, problems);
        }
    }
    

    With this trick I can do whatever I want with the validation. I documented this and added a default project in my companies confluence: https://dev.c-ware.de/confluence/display/PUBLIC/Flexmojos+in+Continuous+Integration+Builds