Rob Avery IV
Rob Avery IV

Reputation: 3730

Maven: Create plugin variable with default-value from another class?

I have a plugin that I'm creating and it has a parameter like so:

/** 
 * Global variable as maven plugin parameter
 * @parameter expression="${plugin.var}" default-value=OtherClass.GLOBAL_VAR
 */
private int var;

I have another class called OtherClass that has a public final static int GLOBAL_VAR;.

How would I be able to set the default-value from a variable from the actual plugin software?

Upvotes: 1

Views: 97

Answers (1)

Stefan Ferstl
Stefan Ferstl

Reputation: 5265

You can just omit the declaration of a default value and assign OtherClass.GLOBAL_VAR directly to var:

/** 
 * Global variable as maven plugin parameter
 * @parameter expression="${plugin.var}"
 */
private int var = OtherClass.GLOBAL_VAR;

As long as ${plugin.var} is not defined, var will not change its value.

Upvotes: 2

Related Questions