You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Evgeny Goldin <ev...@gmail.com> on 2011/01/27 20:46:40 UTC

Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Hi,

I see a different behavior in Maven 2.2.1 and Maven 3.0.2.

Suppose I have

<properties>
    <propertyDir>dir</propertyDir>
</properties>

Later, it is used in expression to configure some plugin:

<configuration>
    <targetPath>pl-290-4/${propertyDir}/1</targetPath>
    ...
</configuration>

*Before* this configuration is running, yet another plugin overrides
${propertyDir}
to another value by calling
mavenProject.getProperties().setProperty( "propertyDir", "dirdir" )

Now, in Maven 2 <configuration> above will see new value and resolve to "
pl-290-4/*dirdir*/1" but in Maven 3
it will see an old one and resolve to "pl-290-4/*dir*/1". As if Maven 2
interpolates ${propertyDir} dynamically
but Maven 3 does so statically so even having ${propertyDir} updated at
run-time the value of expression where
it is involved stays the same.

Here is the POM <http://goo.gl/K3rkS> and if I uncomment line
29<http://goo.gl/JYcsX> expression
in line 143 <http://goo.gl/HEKzq> will create a directory that will fail an
assert in
line 195 <http://goo.gl/YExqW> in Maven 3.0.2 but not in Maven 2.2.1. The
value is overridden in line 62 <http://goo.gl/0wFZs>.

What do you say the correct behavior is?  Is it Maven 3 bug or feature?
Appreciate your help!


Best regards,
Evgeny
evgeny-goldin.com

Re: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Hilco Wijbenga <hi...@gmail.com>.
On 28 January 2011 15:22, lukewpatterson <lu...@gmail.com> wrote:
> * Maven 2 and 3 have different interpolation behavior, and the behavior
> isn't documented in the compatibility notes
> * dynamic variable interpolation doesn't affect determinism, i.e. same input
> yields same output
> * whether the ability furthers traditional builds or "batch processing"
> builds, legitimate use-cases for dynamic interpolation have been identified

Exactly. :-)

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


Re: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.

lukewpatterson wrote:
> 
> In this thread, things that seem to be in agreement so far:
> 
> * Maven 2 and 3 have different interpolation behavior, and the behavior
> isn't documented in the compatibility notes
> * dynamic variable interpolation doesn't affect determinism, i.e. same
> input yields same output
> * whether the ability furthers traditional builds or "batch processing"
> builds, legitimate use-cases for dynamic interpolation have been
> identified
> 

Very good summary!

-----
Best regards,

Evgeny

http://evgeny-goldin.com/ evgeny-goldin.com 

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3362337.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by lukewpatterson <lu...@gmail.com>.
In this thread, things that seem to be in agreement so far:

* Maven 2 and 3 have different interpolation behavior, and the behavior
isn't documented in the compatibility notes
* dynamic variable interpolation doesn't affect determinism, i.e. same input
yields same output
* whether the ability furthers traditional builds or "batch processing"
builds, legitimate use-cases for dynamic interpolation have been identified
-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3362278.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.

Hilco Wijbenga-3 wrote:
> 
> Why would this make it less repeatable? A build's
> repeatability/reproducibility is based on the whether it is
> deterministic. And whether a property can be overwritten/changed
> doesn't change the determinism of a process. If it did, then (single
> threaded) programming would be a lot harder... :-)
> 

In my case the property is changed by Groovy expression meaning it can take
any value at run-time, as a regular application (something that Maven
doesn't like to be, imo, with its focus on repeatability). For me it's not
an issue at all, but for others this behavior may look like something that
varies at run-time, less predictable and, therefore, less repeatable. 

I'll go even further, the POM I run where I have this issue isn't a regular
job building some jars, it is a long process of actions resulting in all
sorts of binaries created. Some data is downloaded from FTP servers and when
FTP servers contain no new files, no binaries are created at all. Next time
you run the same POM, FTP contain updates and binaries are created. Next
time they are created or not, we don't know and don't care.

Repeatability of builds is something we don't need in this case, like we
don't need it when running any kind of background batch processing. We don't
like it when it fails but when it works - any result is totally Ok and we
expect them to be different on each run.

So may be using Maven for this kind of batch processing and not as a "build
tool" contradicts some of its philosophies a little.


-----
Best regards,

Evgeny

http://evgeny-goldin.com/ evgeny-goldin.com 

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3362266.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Hilco Wijbenga <hi...@gmail.com>.
On 28 January 2011 11:10, Evgeny Goldin <ev...@gmail.com> wrote:
> lukewpatterson wrote:
>> The general argument against dynamic properties is that they make the
>> build configuration less declarative, right?
>
> It makes builds more dynamic and less repeatable and that could be the
> reason Maven 3 was changed to behave the way it behaves. Yes, being able to
> update a property in your example can nicely solve a problem of providing an
> expression using this property to another plugin.

Why would this make it less repeatable? A build's
repeatability/reproducibility is based on the whether it is
deterministic. And whether a property can be overwritten/changed
doesn't change the determinism of a process. If it did, then (single
threaded) programming would be a lot harder... :-)

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


Re: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.

lukewpatterson wrote:
> 
> Yeah, it would be nice to have some middle ground for allowing plugins to
> help configure other plugins.  Right now the "Maven Way" is to use the
> file system, right? 
> 

That's the main problem - the "Maven Way" is different in Maven 2 and 3 so I
still don't know if it was done deliberately or resulted by a bug.


lukewpatterson wrote:
> 
> The general argument against dynamic properties is that they make the
> build configuration less declarative, right?
> 

It makes builds more dynamic and less repeatable and that could be the
reason Maven 3 was changed to behave the way it behaves. Yes, being able to
update a property in your example can nicely solve a problem of providing an
expression using this property to another plugin.


-----
Best regards,

Evgeny

http://evgeny-goldin.com/ evgeny-goldin.com 

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3361967.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by lukewpatterson <lu...@gmail.com>.

Evgeny Goldin wrote:
> 
> I think this issue opens a wider one: does Maven treat properties like a
> mutable variables ...
> 

Yeah, it would be nice to have some middle ground for allowing plugins to
help configure other plugins.  Right now the "Maven Way" is to use the file
system, right?  The file system route makes if difficult if the plugin
doesn't "opt-in" to that configuration method.

A great use-case for this dynamic property stuff is seen when wrapping the
JaCoCo code coverage library in a plugin.  One of the beauties of that
library is that it pretty much stays out of the way of your testing
configuration except for needing a vm arg instrumentation entry.

When working on the Maven plugin to wrap the library, I really just want to
help the user configure the vm args, and don't want to get in the business
of launching testing frameworks.  Ideally, I would just ask the user for the
property name they want me to configure (e.g. argLine from surefire), and my
plugin would simply help set that property value.

The general argument against dynamic properties is that they make the build
configuration less declarative, right?
-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3361880.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.
And yes, as a workaround I need not to define anything as <properties>, in
this case it works as expected. The problem with this approach is that POM
becomes very fragile, like in old Ant days: you forget the rule and add a
property that is overridden later .. Whops, but it's not.

I think this issue opens a wider one: does Maven treat properties like a
mutable variables thus allowing more dynamic behavior during the run-time or
it treats them them as a predefined constants, preferring static declarative
behavior and "repeatable builds". It is basically about "dynamicy" vs.
"staticness" or builds.

-----
Best regards,

Evgeny

http://evgeny-goldin.com/ evgeny-goldin.com 

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3361809.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by lukewpatterson <lu...@gmail.com>.

Marc Rohlfs wrote:
> 
> ... It would e.g. be great if I could activate a profile by the 
> existence of a file whose path contains an interpolatable token (like 
> 'src/main/filters/${target.environment}/something.properties'). But I 
> understand that something like this might lead to confusing 
> interpolation behaviour which sometimes could be hard to maintain. 
> 

I think you're right to be concerned about adding extra confusion.  My guess
is that the only way something like this can have a chance is if the target
is limited to the <configuration> section of <plugin>s.  i.e. nothing that
affects the "build plan?"

I'm a little worried that this discussion will quickly be gaftered if the
scope gets too scary or ambitious.

Hog wild sidenote: it would be nice if <configuration> sections could
contain portions that were dynamically generated by other plugins, why stop
at simple properties?
-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3364574.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.
Hi Marc,


Marc Rohlfs wrote:
> 
> What about introducing something like property scopes and/or types?
>    <properties>
>      <my-prop scope="..." type="...">foo</my-prop>
>      <!-- 'scope' = 'global|pom' -->
>      <!-- 'type' = 'mutable|immutable' -->
>    </properties>
> This was just a spontaneous idea, not really well-thought (yet).
> 

Like it, can work really well. Default behavior (no additional attributes)
can be more conservative Ant-like static interpolation but with additional
attributes dynamic interpolation can be turned on. I suggest
interpolation="static|dynamic" attribute.

I checked Maven 2 compatibility now, it works Ok, it ignores additional
attributes:
<properties>
    <propName a="aaaaa" b="cccccc">propValue</propName>



-----
Best regards,

Evgeny

http://evgeny-goldin.com/ evgeny-goldin.com 

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3364531.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Marc Rohlfs <po...@googlemail.com>.
I'll watch this issue as I'm really interested in how it might be handled.

Personally I don't have a clear position here.
Sometimes I'd like the property interpolation to be a little more 
dynamic. It would e.g. be great if I could activate a profile by the 
existence of a file whose path contains an interpolatable token (like 
'src/main/filters/${target.environment}/something.properties'). But I 
understand that something like this might lead to confusing 
interpolation behaviour which sometimes could be hard to maintain. Like 
Luke wrote, those build configurations would be less declarative.

What about introducing something like property scopes and/or types?
   <properties>
     <my-prop scope="..." type="...">foo</my-prop>
     <!-- 'scope' = 'global|pom' -->
     <!-- 'type' = 'mutable|immutable' -->
   </properties>
This was just a spontaneous idea, not really well-thought (yet).


On 28/01/11 18:11, Evgeny Goldin wrote:
> Created an issue:http://jira.codehaus.org/browse/MNG-4998

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


Re: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.
Thanks you, Marc. I hope dynamic behavior will be chosen here, Ant behavior
was known to cause a lot of pain and weird errors that were fixed by
Ant-Contrib <var> task
(http://ant-contrib.sourceforge.net/tasks/tasks/variable_task.html),
defining properties dynamically at any time. Used that *a lot*.

Created an issue: http://jira.codehaus.org/browse/MNG-4998

-----
Best regards,
Evgeny
http://evgeny-goldin.com/

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3361789.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Marc Rohlfs <po...@googlemail.com>.
I'd say properties should be static - otherwise predefining them using 
the command line switch '-D' wouldn't work properly. BTW: With this 
Maven 3 show the same behaviour like Ant (I know, I shouldn't compare 
them), where properties are always immutable.

I just checked it with the the Buildnumber Plugin 
(http://mojo.codehaus.org/buildnumber-maven-plugin):
   <properties>
     <buildNumber>predefined</buildNumber>
   </properties>
   <build>
     <plugins>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>buildnumber-maven-plugin</artifactId>
         <version>1.0-beta-4</version>
         <executions>
           <execution>
             <id>initialize</id>
             <goals>
               <goal>create</goal>
             </goals>
             <phase>initialize</phase>
             <configuration>
               <revisionOnScmFailure>scm-revision</revisionOnScmFailure>
             </configuration>
           </execution>
         </executions>
       </plugin>
       <plugin>
         <artifactId>maven-antrun-plugin</artifactId>
         <version>1.6</version>
         <executions>
           <execution>
             <id>echo</id>
             <goals>
               <goal>run</goal>
             </goals>
             <phase>generate-sources</phase>
             <configuration>
               <target>
                 <echo message="${buildNumber}" />
               </target>
             </configuration>
           </execution>
         </executions>
       </plugin>
     </plugins>
   </build>
It shows exactly the same behaviour: with Maven 2 it prints 
'scm-revision' and with Maven 3 it prints 'predefined'. Maybe it might 
help You if You file an issue in the Jira for that component.

Maybe as a workaround You could introduce something like a 
'defaultValue' for each property in Your plugin configuration(s).

Kind regards, Marc


On 27/01/11 20:55, Evgeny Goldin wrote:
>
> But it can be perfectly changed in Maven 2 and I use it a lot. It's just that
> in Maven 3 the expression doesn't reflect the change out of sudden.
>
> -----
> Best regards,
> Evgeny
> http://evgeny-goldin.com/
>

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


Re: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by Evgeny Goldin <ev...@gmail.com>.
But it can be perfectly changed in Maven 2 and I use it a lot. It's just that
in Maven 3 the expression doesn't reflect the change out of sudden. 

-----
Best regards,
Evgeny
http://evgeny-goldin.com/

-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3360350.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: Variables interpolation: dynamic in Maven 2, static in Maven 3 ?

Posted by lukewpatterson <lu...@gmail.com>.
I seem to remember it always being static.  I remember trying that scenario
in Maven 2 and it always remained the same as what was present in
help:effective-pom.  i.e. if it shows up in effective-pom, your plugin can't
change it
-- 
View this message in context: http://maven.40175.n5.nabble.com/Variables-interpolation-dynamic-in-Maven-2-static-in-Maven-3-tp3360336p3360344.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