You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Pulkit Singhal <pu...@gmail.com> on 2010/08/20 01:20:24 UTC

Shuttling Property Values between Maven and Ant

Hello,

Can anyone tell me how to make sure that the property values changed
by the antrun plugin stick around for use by Maven?

I have defined the following properties in Maven:

    <properties>
        <!-- valid values: developer or production -->
        <BUILD_TYPE>developer</BUILD_TYPE>
        <DEVELOPER_BUILD>false</DEVELOPER_BUILD>
        <PRODUCTION_BUILD>false</PRODUCTION_BUILD>
    </properties>

And I'm trying to operate on them and change their default values via
the maven-antrun-plugin:
   <condition property="DEVELOPER_BUILD" value="true" else="false">
       <equals arg1="${BUILD_TYPE}" arg2="developer"/>
   </condition>
   <condition property="PRODUCTION_BUILD" value="true" else="false">
       <equals arg1="${BUILD_TYPE}" arg2="production"/>
   </condition>

When I echo the property values before and after the conditions in the
antrun plugin, I can see the maven values coming in and the
appropriate conditions changing those values from false to true.

But when I try to use the property values (that should have been
altered by the antrun plugin) in Maven again, they are not available.
Only the original values from Maven are available!
   <definesDeclaration>
       <property>
           <name>BUILD_TYPE::developer</name>
           <value>${DEVELOPER_BUILD}</value>
       </property>
       <property>
           <name>BUILD_TYPE::production</name>
           <value>${PRODUCTION_BUILD}</value>
       </property>
   </definesDeclaration>

Can anyone tell me how to make sure that the property values changed
by the antrun plugin stick around for use by Maven?

Thanks!

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


Re: Shuttling Property Values between Maven and Ant

Posted by Pulkit Singhal <pu...@gmail.com>.
Hello Luke,

Thank You for the help. I see that props can be written out and read
back in and this has to be done explicitly to get the altered values
back from ant.

By the way I tried using profiles and I was able to accomplish the
separation I needed for my compile time variables based on any maven
command line input so I went that way for now. But I really needed to
know on principle if passing back from ant to maven could be done or
not and it seems that it would be a very manual task :(

On Fri, Aug 20, 2010 at 7:16 AM, lukewpatterson
<lu...@gmail.com> wrote:
>
> ... more background info, trying to be more accurate and complete this time,
> if anyone sees anything that should be clarified, please jump in ...
>
>
> antrun is able to see property value changes during an <execution> run
> because of two things:
>
> * it is manually pulling xml out of its own configuration section [1], and
> resolving the expressions it each time it comes across them during ant
> execution
> * during the run, the properties are ant properties (initialized with
> corresponding maven property values), and don't get written back to maven
> properties unless you explicitly do so [2]
>
>
> other plugins typically wouldn't be doing this, and instead rely on whatever
> is passed in from the container, the stuff passed in from the container is
> whatever is seen in help:effective-pom (things explicitly declared in
> configuration sections) plus resolutions of default values (if the default
> values contain expressions, they are evaluated right before the plugin runs)
>
>
>
> [1]
> http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?view=markup
> (line 457 is a interesting spot)
> [2]
> http://maven.40175.n5.nabble.com/Exporting-Ant-properties-to-Maven-td510023.html#a510117
> --
> View this message in context: http://maven.40175.n5.nabble.com/Shuttling-Property-Values-between-Maven-and-Ant-tp2641670p2642018.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
>
>

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


Re: Shuttling Property Values between Maven and Ant

Posted by lukewpatterson <lu...@gmail.com>.
... more background info, trying to be more accurate and complete this time,
if anyone sees anything that should be clarified, please jump in ...


antrun is able to see property value changes during an <execution> run
because of two things:

* it is manually pulling xml out of its own configuration section [1], and
resolving the expressions it each time it comes across them during ant
execution
* during the run, the properties are ant properties (initialized with
corresponding maven property values), and don't get written back to maven
properties unless you explicitly do so [2]


other plugins typically wouldn't be doing this, and instead rely on whatever
is passed in from the container, the stuff passed in from the container is
whatever is seen in help:effective-pom (things explicitly declared in
configuration sections) plus resolutions of default values (if the default
values contain expressions, they are evaluated right before the plugin runs)



[1]
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?view=markup
(line 457 is a interesting spot)
[2]
http://maven.40175.n5.nabble.com/Exporting-Ant-properties-to-Maven-td510023.html#a510117
-- 
View this message in context: http://maven.40175.n5.nabble.com/Shuttling-Property-Values-between-Maven-and-Ant-tp2641670p2642018.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: Shuttling Property Values between Maven and Ant

Posted by lukewpatterson <lu...@gmail.com>.
AFAIK, so if you're trying to configure another plugin with those properties
(i.e. using properties in the plugin's configuration section), you can only
"see" the antrun-updated values if you don't explicitly reference the
properties in the POM, but instead rely on lazily-resolved expressions

i.e./e.g. 

if configuring invoker, and you want to set the ignoreFailures [1]
configuration element, any value you set in the pom, whether direct or
through a property, is resolved once and only once, before validate runs

OTOH, if you leave out the <ignoreFailures> configuration element, and
instead set ${maven.test.failure.ignore} (its mapped expression) with
antrun, the plugin will see the value as long as it was called after antrun

hope that makes sense, long day, rambling answer


[1]
http://maven.apache.org/plugins/maven-invoker-plugin/run-mojo.html#ignoreFailures
-- 
View this message in context: http://maven.40175.n5.nabble.com/Shuttling-Property-Values-between-Maven-and-Ant-tp2641670p2641691.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