Mapping complex objects in maven plugin

427 views Asked by At

I want to configure some complex objects in maven plugin .. like -

<?xml version="1.0" encoding="UTF-8"?>
<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.test.helloworld</groupId>
   <artifactId>hw</artifactId>
   <version>1.0.0</version>
   <packaging>jar</packaging>
   <build>
     <plugins>
       <plugin>
           <groupId>com.test.my.maven.plugin</groupId>
           <artifactId>my-maven-plugin</artifactId>
           <version>1.0.0</version>
           <extensions>true</extensions>
           <configuration>
               <myObject>
                  <name>mike</name>
                  <age>23</age>
                  <props>
                     <property>
                       <key>test</key>
                       <value>testValue</value>
                     </property>
                  </props>
                </myObject>
              </configuration> 
            </plugin>
         </plugins>
      </build>
    </project>

And here is my sample mojo in which I want to use these configurations -

public class testMojo extends AbstractMojo{

    @Parameter
    private Map<String, Object> myObject;
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
      String name = (String)myObject.get("name");
      String age = (String)myObject.get("age");
      Properties props = (Properties)myObject.get("props");
     }

}

But it gives me null value for myObject. I have tried creating a class as mentioned here Even it gives me null value. How can i do such complex mapping in maven mojo ?

0

There are 0 answers