'How to specify Maven plugin property from command line if "property" is not set?

This is how my Maven plugin looks:

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "my", defaultPhase = LifecyclePhase.COMPILE)
public class MyMojo extends AbstractMojo {
  @Parameter
  protected String foo;
  // the rest of the code skipped
}

I can call it form command line:

$ mvn my:my

But I don't know how to set foo using -D. What is the right way to specify it from the command line without adding property attribute to the @Parameter annotation?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source