String arrays as command line arguments for maven plugin

后端 未结 5 1171
轻奢々
轻奢々 2020-12-06 16:35

I\'m writing a maven plugin that has a parameter that\'s a String[].

Like this:

/**
* @parameter expression=\"${args}\"
*/
protected String[] args;
<         


        
5条回答
  •  眼角桃花
    2020-12-06 17:29

    You can't do it directly as far as I know, but it is pretty common practice to accept a delimited String and split that into an array yourself.

    For example the maven-site-plugin allows you to specify a comma-delimited String of locales, while the maven-scala-plugin handles this by allowing you to define the arguments with a pipe separator. You can look at the relevant Mojos to see how the argument is processed.

    Some example usages below:

    site-plugin:

    -Dlocales=enGB,frFR
    

    scala-plugin:

    -DaddArgs=arg1|arg2|arg3
    

    Update: if you want to handle this more elegantly, you could use maven-shared-io to allow definition of an external descriptor file, then pass the descriptor location as a property. This means a single command-line argument can reference a structure of configuration.

    If this sounds like it might work for you, have a look at this answer that describes how to use external descriptors in the properties plugin, or this answer that does similar for the xml-maven-plugin. Or you can just look at the assembly-plugin for ideas.

提交回复
热议问题