5

Reading up on the guide for developing maven plugins I see that you can define list parameters and arbitrary object parameters, but is it possible to define a parameter that id a list of objects, defined as:

/**
 * @parameter
 */
private List<MyObject> objects;
mac
  • 5,627
  • 1
  • 18
  • 21

2 Answers2

6

Sure - I do this all the time. Make sure MyObject is a Java bean with each attribute annotated with @parameter, etc. just as you would if each parameter were in the Mojo itself.

tdrury
  • 2,307
  • 1
  • 22
  • 25
3

I didn't even annotate anything in MyObject, just list parameter.

@Parameter(property = "versioning.scripts")
private List<MyObject> scripts;

and all is working fine anyway.

Boris Mitioglov
  • 1,092
  • 4
  • 16
  • 32
  • is there anything more to do with the custom class? I'm currently trying to create a simple person class, like in http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Mapping_Complex_Objects but I always get the following error: Unable to parse configuration of mojo ... for parameter person: Cannot create instance of class ...$Person Person class looks like this: public class Person { protected String firstName; protected String lastName; } – Fabian Köbel Jun 20 '16 at 14:26
  • question solved: Person must not be an inner class http://stackoverflow.com/questions/37921848/maven-mojo-mapping-complex-objects?noredirect=1#comment63302174_37921848 – Fabian Köbel Jun 20 '16 at 19:06