You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by daition <da...@163.com> on 2009/01/16 03:59:20 UTC

How to update property value of POM.xml in a maven plugin?

Hi,
 
I have a question about developing maven plugin.
 
A plugin can get the property value of POM.xml, as "@parameter" annotation does.
But how can I create a new property in maven plugin, which can also be accessed in POM.xml? 
That is, how can I update the property value of POM.xml in a maven plugin?
I have searched for the documents, but no example found. Could anyone help to give an example?
 
Thanks!
Delos

Re: How to update property value of POM.xml in a maven plugin?

Posted by daition <ke...@gmail.com>.
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?


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
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-update-property-value-of-POM.xml-in-a-maven-plugin--tp21492944p21558582.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to update property value of POM.xml in a maven plugin?

Posted by Stephen Connolly <st...@gmail.com>.
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
>
>

Re: How to update property value of POM.xml in a maven plugin?

Posted by 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>


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