maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Marti <thx...@schweiz.org>
Subject Re: How to set build properties from a Mojo
Date Wed, 11 Mar 2009 22:24:25 GMT
Hi Paul

Depending on what you need, this is not entirely trivial. If you just want to 
set property 'foo' to value 'bar', then the approach below is just fine. But say 
you have a property 'baz' in your pom like this:
<properties>
   <baz>xx${foo}xx</baz>
</properties>

And you want 'baz' to evaluate to 'xxbarxx', then you need a bit more logic in 
your Mojo. As is described here => http://plexus.codehaus.org/plexus-interpolation/


Greetings,
  Thomas

Paul wrote:
> Le mercredi 11 mars 2009 19:24:20, Nord, James a écrit :
>> The following will set a variable I_WAS_HERE to "true".
> 
> Thanks, that's what I was looking for.
> Simple :)
> 
> Paul
> 
> 
>> /**
>>  * Goal which stores some properties
>>  *
>>  * @goal getProperty
>>  * @phase validate
>>  */
>> The following gets the maven version and stores it as the maven.version
>> property.
>>
>> public class MavenPropertiesMojo extends AbstractMojo {
>>
>>
>> 	/**
>> 	 * The Maven project.
>> 	 *
>> 	 * @parameter expression="${project}"
>> 	 * @required
>> 	 * @readonly
>> 	 */
>> 	private MavenProject        project;
>>
>> 	/**
>> 	 * @component
>> 	 */
>> 	private RuntimeInformation  runtime;
>>
>>
>> 	public void execute() throws MojoExecutionException {
>>
>> 		project.getProperties().put("I_WAS_HERE", "true");
>> 	}
>>
>> }
> 
> 

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


Mime
View raw message