Limit Java maven plugin configuration options

I am writing a maven plugin with several custom options. The Mojo class has a number of parameters. One of these parameters is required and must contain certain values ​​(say, either Atwood or Spolsky). At the moment, it is annotated using. @required field as shown here:

public class GenerateMojo extends AbstractMojo{
   ...
   ...

   /**
   *@parameter
   *@required
   */
   private String someParameter;
   ...
   ...
}

That all is well and good, but if someone forgets to enable the parameter, he receives a general error message:

Inside the definition for plugin 'xyz' specify the following:
<configuration>    
    ...   
    <someParameter>VALUE</someParameter>
</configuration>

If it is possible (1) to limit the values ​​that can be entered in the someParmeter field to give a better error message, or (2) specify the error message myself, so that I can write something like "Value for", someParameter should be either "Atwood" or "Spolsky"

thanks

+3
1

Jira, Maven 2.2 ( Plexus Java 5).

, Mojo . execute() .

, , execute(), , , . :

/**
 * @parameter expression="${someParameter}" default-value="_"
 */
private String someParameter;
+2

Source: https://habr.com/ru/post/1715646/


All Articles