Using map of maps as Maven plugin parameters

前端 未结 2 1576
既然无缘
既然无缘 2021-01-06 11:48

Is it possible to use a map of maps as a Maven plugin parameter?, e.g.

@Parameter
private Map

        
2条回答
  •  别那么骄傲
    2021-01-06 12:16

    One solution is quite simple and works for 1-level nesting. A more sophisticated approach can be found in the alternative answer which possibly also allows for deeper nesting of Maps.

    Instead of using an interface as type parameter, simply use a concrete class like TreeMap

     @Parameter
     private Map converters.
    

    The reason is this check in MapConverter which fails for an interface but suceeds for a concrete class:

       private static Class findElementType( final Type[] typeArguments )
       {
           if ( null != typeArguments && typeArguments.length > 1 
                && typeArguments[1] instanceof Class )
           {
               return (Class) typeArguments[1];
           }
           return Object.class;
       }
    

    As a side-note, an as it is also related to this answer for Maven > 3.3.x it also works to install a custom converter by subclassing BasicComponentConfigurator and using it as a Plexus component. BasicComponentConfigurator has the DefaultConverterLookup as a protected member variable and is hence easily accessible for registering custom converters.

提交回复
热议问题