You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Paul <pa...@nosphere.org> on 2009/03/11 19:02:53 UTC

How to set build properties from a Mojo

I need to write a mojo that reads some data and makes it available in the pom 
as ${properties}.

Is there a way to achieve this ?



Re: How to set build properties from a Mojo

Posted by Paul <pa...@nosphere.org>.
Thomas,

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

That could have been a trap without you, thanks Thomas !

Regards

Paul

Re: How to set build properties from a Mojo

Posted by Thomas Marti <th...@schweiz.org>.
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


Re: How to set build properties from a Mojo

Posted by Paul <pa...@nosphere.org>.
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");
> 	}
>
> }


RE: How to set build properties from a Mojo

Posted by "Nord, James" <JN...@nds.com>.
The following will set a variable I_WAS_HERE to "true".

/**
 * 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");
	}
	
} 

> -----Original Message-----
> From: Paul [mailto:paul@nosphere.org] 
> Sent: 11 March 2009 18:03
> To: Maven Developers List
> Subject: How to set build properties from a Mojo
> 
> I need to write a mojo that reads some data and makes it 
> available in the pom as ${properties}.
> 
> Is there a way to achieve this ?
> 
> 
> 

**************************************************************************************
This e-mail is confidential, the property of NDS Ltd and intended for the addressee only. Any dissemination, copying or distribution of this message or any attachments by anyone other than the intended recipient is strictly prohibited. If you have received this message in error, please immediately notify the postmaster@nds.com and destroy the original message. Messages sent to and from NDS may be monitored. NDS cannot guarantee any message delivery method is secure or error-free. Information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. We do not accept responsibility for any errors or omissions in this message and/or attachment that arise as a result of transmission. You should carry out your own virus checks before opening any attachment. Any views or opinions presented are solely those of the author and do not necessarily represent those of NDS.

To protect the environment please do not print this e-mail unless necessary.

NDS Limited Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales Registered no. 3080780 VAT no. GB 603 8808 40-00
**************************************************************************************

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


Re: How to set build properties from a Mojo

Posted by Paul <pa...@nosphere.org>.
Le mercredi 11 mars 2009 19:21:45, Paul Gier a écrit :
> Maybe the properties maven plugin does something similar to what you want.
> http://mojo.codehaus.org/properties-maven-plugin/

I was not aware of this one, thanks for the pointer it can be usefull !


Re: How to set build properties from a Mojo

Posted by Paul Gier <pg...@redhat.com>.
Maybe the properties maven plugin does something similar to what you want.
http://mojo.codehaus.org/properties-maven-plugin/

Paul wrote:
> I need to write a mojo that reads some data and makes it available in the pom 
> as ${properties}.
> 
> Is there a way to achieve this ?
> 
> 
> 


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