You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Laird Nelson <lj...@gmail.com> on 2011/09/10 00:32:15 UTC
Maven plugin: set value in constructor, no longer configured by Maven?
Suppose I have a plugin parameter like this:
/**
* @parameter *default-value="hoopy"* property="disposition"
*/
private String disposition;
...and a getter/setter pair like this:
public String getDisposition() {
return this.disposition;
}
public void setDisposition(final String disposition) {
this.disposition = disposition;
}
...then when my mojo is loaded and configured by Maven it will call my
setter method with "hoopy" (the plugin parameter's defaultValue value) if I
haven't used a <configuration> element with a <disposition> element inside
it.
Now suppose additionally I have a constructor like this:
public MyMojo() {
super();
* this.setDisposition("crabby");*
}
I am observing in my plugin tests (based on the
maven-plugin-testing-harness<http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/>machinery,
using
configureMojo()<http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/apidocs/org/apache/maven/plugin/testing/AbstractMojoTestCase.html#configureMojo%28org.apache.maven.plugin.Mojo,%20java.lang.String,%20java.io.File%29>)
that if my constructor contains a setter call, Maven (or Plexus, I guess?)
does not subsequently call setDisposition() with "hoopy" ever. Does it do
some kind of a getDisposition() == null test first to decide whether to
configure my plugin? Why, if so?
I would think that whatever I do in my constructor is my business, and that
if my XML configuration does not supply a value, Maven would supply the
defaultValue of the @parameter, perhaps (justifiably) overwriting anything
that I might have set up in my constructor. Why does Maven/Plexus not do
this? Or what have I misunderstood?
Best,
Laird
--
http://about.me/lairdnelson
Re: Maven plugin: set value in constructor, no longer configured by Maven?
Posted by Laird Nelson <lj...@gmail.com>.
On Fri, Sep 9, 2011 at 6:32 PM, Laird Nelson <lj...@gmail.com> wrote:
> I am observing in my plugin tests (based on the
> maven-plugin-testing-harness<http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/>machinery, using
> configureMojo()<http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/apidocs/org/apache/maven/plugin/testing/AbstractMojoTestCase.html#configureMojo%28org.apache.maven.plugin.Mojo,%20java.lang.String,%20java.io.File%29>)
> that if my constructor contains a setter call, Maven (or Plexus, I guess?)
> does not subsequently call setDisposition() with "hoopy" ever.
>
Please disregard the noise I just made; pilot error; sorry.
Best
Laird
--
http://about.me/lairdnelson