You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Stephen Connolly <st...@gmail.com> on 2009/01/18 08:24:23 UTC
Re: How to update property value of POM.xml in a maven plugin?
I think you replied to the wrong address.
2009/1/18 <ke...@gmail.com>
> Carlo
>
> Thanks a lot!
>
> I have tried this method. But I have another problem:
>
> I declare the mojo in root pom.xml and the property added in mojo can be
> reference with ${propertyName}. But in the pom.xml of sub module, the
> property can't be referenced like this. It seems no such property added in
> mojo.
>
> What's the reason? Is there any solution?
>
I suspect that the reason is the child pom's properties are inferred when
building the model, which is before your plugin's mojo runs
>
> I'm a new to maven, so really appreciate your help -:)
>
> Stephen Connolly-2 wrote:
> >
> > 2009/1/16 Carlo Sciolla <ca...@gmail.com>
> >
> >> Something like this:
> >>
> >> <code>
> >> // MyMojo.java
> >>
> >> /**
> >> * The Maven project
> >> * @parameter expression="${project}"
> >> * @required
> >> */
> >> private MavenProject project;
> >>
> >> [...]
> >>
> >> public void execute()
> >> throws MojoExecutionException
> >> {
> >> [...]
> >> project.getProperties().put("propertyAvailableHereafter",
> >> actualValue);
> >> [...]
> >> }
> >> }
> >> </code>
> >>
> >
> > But note that this property will only be available to phases after your
> > mojo
> > has executed....
> >
> > This can cause fun if you want to use the property value in the pom in an
> > expression that is used when the initial model is being constructed (i.e.
> > you cannot use the property in /project/artifactId, etc)
> >
> >
> >>
> >>
> >> Hope this helps,
> >> c.
> >>
> >> --
> >> Carlo Sciolla - http://www.skuro.tk
> >> Software Engineer at Sourcesense - Making sense of open Source
> >> (http://www.sourcesense.com)
> >> Linux User #372086
> >>
> >> \|/
> >> -(o< -- I'm a punk, dude!
> >> //\
> >> V_/_
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
> >
> Quoted from:
>
> http://www.nabble.com/How-to-update-property-value-of-POM.xml-in-a-maven-plugin--tp21492944p21500409.html
>
>
Re: How to update property value of POM.xml in a maven plugin?
Posted by Dan Tran <da...@gmail.com>.
On Sat, Jan 17, 2009 at 11:24 PM, Stephen Connolly
<st...@gmail.com> wrote:
> I think you replied to the wrong address.
>
> 2009/1/18 <ke...@gmail.com>
>
>> Carlo
>>
>> Thanks a lot!
>>
>> I have tried this method. But I have another problem:
>>
>> I declare the mojo in root pom.xml and the property added in mojo can be
>> reference with ${propertyName}. But in the pom.xml of sub module, the
>> property can't be referenced like this. It seems no such property added in
>> mojo.
>>
>> What's the reason? Is there any solution?
>>
Use maven-2.1-M1, it has fixed the bug you encounter. See
build-helper-maven-plugin source and example to see some discussions
about this
>
> I suspect that the reason is the child pom's properties are inferred when
> building the model, which is before your plugin's mojo runs
>
>
>>
>> I'm a new to maven, so really appreciate your help -:)
>>
>> Stephen Connolly-2 wrote:
>> >
>> > 2009/1/16 Carlo Sciolla <ca...@gmail.com>
>> >
>> >> Something like this:
>> >>
>> >> <code>
>> >> // MyMojo.java
>> >>
>> >> /**
>> >> * The Maven project
>> >> * @parameter expression="${project}"
>> >> * @required
>> >> */
>> >> private MavenProject project;
>> >>
>> >> [...]
>> >>
>> >> public void execute()
>> >> throws MojoExecutionException
>> >> {
>> >> [...]
>> >> project.getProperties().put("propertyAvailableHereafter",
>> >> actualValue);
>> >> [...]
>> >> }
>> >> }
>> >> </code>
>> >>
>> >
>> > But note that this property will only be available to phases after your
>> > mojo
>> > has executed....
>> >
>> > This can cause fun if you want to use the property value in the pom in an
>> > expression that is used when the initial model is being constructed (i.e.
>> > you cannot use the property in /project/artifactId, etc)
>> >
>> >
>> >>
>> >>
>> >> Hope this helps,
>> >> c.
>> >>
>> >> --
>> >> Carlo Sciolla - http://www.skuro.tk
>> >> Software Engineer at Sourcesense - Making sense of open Source
>> >> (http://www.sourcesense.com)
>> >> Linux User #372086
>> >>
>> >> \|/
>> >> -(o< -- I'm a punk, dude!
>> >> //\
>> >> V_/_
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> >> For additional commands, e-mail: users-help@maven.apache.org
>> >>
>> >>
>> >
>> >
>> Quoted from:
>>
>> http://www.nabble.com/How-to-update-property-value-of-POM.xml-in-a-maven-plugin--tp21492944p21500409.html
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org