You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Karl Heinz Marbaise <kh...@gmx.de> on 2015/08/23 17:16:07 UTC

Using ${revision} as a version

Hi,

I have test project where i defined the pom like this:

...
   <modelVersion>4.0.0</modelVersion>

   <groupId>com.soebes.examples.j2ee</groupId>
   <artifactId>parent</artifactId>
   <version>${revision}</version>
   <packaging>pom</packaging>

If i define the revision on command line like this.

mvn -Drevision=1.0-SNAPSHOT clean package

everything fine...

But now i want to make the usage a bit more convenient so i added the 
following to my pom:


   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <revision>1.0-SNAPSHOT</revision>
   </properties>

to have a default for revision which works fine now...

But if i would like to overwrite the property from command line like this:

mvn -Drevision=1.0 clean package

the build failes in the following location:

[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (assemblies) 
on project assembly: Failed to create assembly: Unable to resolve 
dependencies for assembly 'archive': Failed to resolve dependencies for 
assembly: Unable to get dependency information for 
com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Failed to 
process POM for 
com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Non-resolvable 
parent POM for 
com.soebes.examples.j2ee:service-client:[unknown-version]: Failure to 
find com.soebes.examples.j2ee:parent:pom:${revision} in 
http://localhost:8081/nexus/content/groups/public was cached in the 
local repository, resolution will not be reattempted until the update 
interval of nexus has elapsed or updates are forced
[ERROR] com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT

The project is available on github 
(https://github.com/khmarbaise/javaee/tree/mvn321)....

So the question which is coming up...is this based on Maven core or is 
this based on maven-assembly-plugin ?

Kind regards
Karl Heinz Marbaise

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


RE: Using ${revision} as a version

Posted by Martin Gainty <mg...@hotmail.com>.




> Date: Sun, 23 Aug 2015 17:16:07 +0200
> From: khmarbaise@gmx.de
> To: dev@maven.apache.org
> Subject: Using ${revision} as a version
> 
> Hi,
> 
> I have test project where i defined the pom like this:
> 
> ...
>    <modelVersion>4.0.0</modelVersion>
> 
>    <groupId>com.soebes.examples.j2ee</groupId>
>    <artifactId>parent</artifactId>
>    <version>${revision}</version>
>    <packaging>pom</packaging>
> 
> If i define the revision on command line like this.
> 
> mvn -Drevision=1.0-SNAPSHOT clean package
> 
> everything fine...
MG>so launcher ingests revision property from System.getProperties()
MG>  package org.codehaus.plexus.classworlds.launcher;
   public class Configurator  implements ConfigurationHandler
 {
    public void configure( InputStream is )
        throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
    {
        if ( world == null )
        {
            world = new ClassWorld();
        }
        curRealm = null;
        foreignClassLoader = null;
        if ( this.launcher != null )
        {
            foreignClassLoader = this.launcher.getSystemClassLoader();
        }
        ConfigurationParser parser = new ConfigurationParser( this, System.getProperties() );
MG>CLI seems to be obtaining properties properly..so far so good... but look below:

> But now i want to make the usage a bit more convenient so i added the 
> following to my pom:
> 
> 
>    <properties>
>      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>      <revision>1.0-SNAPSHOT</revision>
>    </properties>
> 
> to have a default for revision which works fine now...
> 
> But if i would like to overwrite the property from command line like this:
> 
> mvn -Drevision=1.0 clean package
> 
> the build failes in the following location:
> 
> [ERROR] Failed to execute goal 
> org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (assemblies) 
> on project assembly: Failed to create assembly: Unable to resolve 
> dependencies for assembly 'archive': Failed to resolve dependencies for 
> assembly: Unable to get dependency information for 
> com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Failed to 
> process POM for 
> com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Non-resolvable 
> parent POM for 
> com.soebes.examples.j2ee:service-client:[unknown-version]: Failure to 
> find com.soebes.examples.j2ee:parent:pom:${revision} in 
> http://localhost:8081/nexus/content/groups/public was cached in the 
> local repository, resolution will not be reattempted until the update 
> interval of nexus has elapsed or updates are forced
> [ERROR] com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT
> 
> The project is available on github 
> (https://github.com/khmarbaise/javaee/tree/mvn321)....
> 
> So the question which is coming up...is this based on Maven core or is 
> this based on maven-assembly-plugin ?

MG>but in Maven-core    :
MG>org.apache.maven.plugin
MG>public class PluginParameterExpressionEvaluator    implements TypeAwareExpressionEvaluator
MG>@Override
MG>public Object evaluate( String expr, Class<?> type ) throws ExpressionEvaluationException
MG>....
MG>if ( value == null )
        {
            // The CLI should win for defining properties
            if ( properties != null )
            {
                // We will attempt to get nab a system property as a way to specify a
                // parameter to a plugins. My particular case here is allowing the surefire
                // plugin to run a single test so I want to specify that class on the cli
                // as a parameter.
                value = properties.getProperty( expression );
            }
            if ( ( value == null ) && ( ( project != null ) && ( project.getProperties() != null ) ) )
            {
                value = project.getProperties().getProperty( expression );
            }
        }
MG>so it appears CLI is supposed to win over any properties defined within project pom.xml
MG>but CLI implementation becomes inconsistent when project properties has version already defined in project pom.xml
MG>behaviour resulting from object graph produced by the reactor from CLI properties appears to be undefined and ultimately causes Exception
MG>I think you found a Bug Karl
> 
> Kind regards
> Karl Heinz Marbaise
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 

 		 	   		  

Re: Using ${revision} as a version

Posted by Lennart Jörelid <le...@gmail.com>.
I have painfully noted that the currently only [properly] working way is to
use profiles to
switch between values given on the command line and some type of default
value (given in another profile).

Typically, it takes on the pattern/form as shown below - and it would be
really nice not to have to resort to these kinds of things. Instead, it
would be cleaner if these types of profile workaround patterns would not be
needed, instead simply overriding a property from the CLI.

Question, though: Would overriding properties from the CLI in some way be
contradictory to the requirement of a repeatable build?

<!--
    Tokenization profile for Development builds.

    Use: -Dtarget_environment=development
-->
<profile>
    <id>tokenization_development</id>
    <activation>
        <property>
            <name>!target_environment</name>
        </property>
    </activation>

    <properties>
        <target_environment>development</target_environment>
        <tokens.environment>${token.dir}/environments/${target_environment}.properties</tokens.environment>
    </properties>
</profile>

<!--
    Tokenization profile for Test builds.

    Use: -Dtarget_environment=test
-->
<profile>
    <id>tokenization_test</id>
    <activation>
        <property>
            <name>target_environment</name>
            <value>test</value>
        </property>
    </activation>

    <properties>
        <target_environment>test</target_environment>
        <tokens.environment>${token.dir}/environments/${target_environment}.properties</tokens.environment>
    </properties>
</profile>


2015-09-26 22:46 GMT+02:00 Karl Heinz Marbaise <kh...@gmx.de>:

> Hi,
>
> so after diving into this problem... (
> https://issues.apache.org/jira/browse/MNG-5895)...
>
> I have found the culprit (in my opinion) at Maven-assembly-plugin located
> in this class DefaultDependencyResolver:
>
> at the following method:
>
>
>     private Set<Artifact> resolveTransitively(
> final Set<Artifact> dependencyArtifacts,
> final List<ArtifactRepository> repos,
> final ResolutionManagementInfo info,
> final AssemblerConfigurationSource configSource )
>  throws DependencyResolutionException
>     {
>         final MavenProject project = configSource.getProject();
>
>         final ArtifactFilter filter = info.getScopeFilter();
>
>         ArtifactResolutionRequest req = new ArtifactResolutionRequest();
>         req.setLocalRepository( configSource.getLocalRepository() );
>         req.setResolveRoot( false );
>         req.setRemoteRepositories( repos );
>         req.setResolveTransitively( true );
>         req.setArtifact( project.getArtifact() );
>         req.setArtifactDependencies( dependencyArtifacts );
>         req.setManagedVersionMap( project.getManagedVersionMap() );
>         req.setCollectionFilter( filter );
>         req.setOffline( configSource.getMavenSession().isOffline() );
>         req.setForceUpdate(
> configSource.getMavenSession().getRequest().isUpdateSnapshots() );
>         req.setServers(
> configSource.getMavenSession().getRequest().getServers() );
>         req.setMirrors(
> configSource.getMavenSession().getRequest().getMirrors() );
>         req.setProxies(
> configSource.getMavenSession().getRequest().getProxies() );
>
>         ArtifactResolutionResult result;
>
>         result = resolver.resolve( req );
>         if ( result.hasExceptions() )
>         {
>             throw new DependencyResolutionException( "Failed to resolve
> dependencies for assembly: ",
>
> result.getExceptions().get( 0 ) );
>         }
>
>         FilterUtils.reportFilteringStatistics( Collections.singleton(
> filter ), getLogger() );
>
>         return result.getArtifacts();
>     }
>
>
>
> And the identified line is:
>
>         result = resolver.resolve( req );
>
> which fails to find the appropriate dependencies...or better the wrong
> version of the dependencies....
>
>
> So I'm not sure at the moment if this is based on Maven 2 compatibility of
> maven-assembly-plugin or if there is an other issue in there or I'm just
> simply wrong...
>
> WDYT ?
>
>
> Kind regards
> Karl Heinz Marbaise
>
>
>
> On 8/23/15 5:16 PM, Karl Heinz Marbaise wrote:
>
>> Hi,
>>
>> I have test project where i defined the pom like this:
>>
>> ...
>>    <modelVersion>4.0.0</modelVersion>
>>
>>    <groupId>com.soebes.examples.j2ee</groupId>
>>    <artifactId>parent</artifactId>
>>    <version>${revision}</version>
>>    <packaging>pom</packaging>
>>
>> If i define the revision on command line like this.
>>
>> mvn -Drevision=1.0-SNAPSHOT clean package
>>
>> everything fine...
>>
>> But now i want to make the usage a bit more convenient so i added the
>> following to my pom:
>>
>>
>>    <properties>
>>      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>>      <revision>1.0-SNAPSHOT</revision>
>>    </properties>
>>
>> to have a default for revision which works fine now...
>>
>> But if i would like to overwrite the property from command line like this:
>>
>> mvn -Drevision=1.0 clean package
>>
>> the build failes in the following location:
>>
>> [ERROR] Failed to execute goal
>> org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (assemblies)
>> on project assembly: Failed to create assembly: Unable to resolve
>> dependencies for assembly 'archive': Failed to resolve dependencies for
>> assembly: Unable to get dependency information for
>> com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Failed to
>> process POM for
>> com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Non-resolvable
>> parent POM for
>> com.soebes.examples.j2ee:service-client:[unknown-version]: Failure to
>> find com.soebes.examples.j2ee:parent:pom:${revision} in
>> http://localhost:8081/nexus/content/groups/public was cached in the
>> local repository, resolution will not be reattempted until the update
>> interval of nexus has elapsed or updates are forced
>> [ERROR] com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT
>>
>> The project is available on github
>> (https://github.com/khmarbaise/javaee/tree/mvn321)....
>>
>> So the question which is coming up...is this based on Maven core or is
>> this based on maven-assembly-plugin ?
>>
>> Kind regards
>> Karl Heinz Marbaise
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>


-- 

--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: lj@jguru.se
| URL:   www.jguru.se
| Phone
| (skype):    jgurueurope
| (intl):     +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+

Re: Using ${revision} as a version

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi,

so after diving into this problem... 
(https://issues.apache.org/jira/browse/MNG-5895)...

I have found the culprit (in my opinion) at Maven-assembly-plugin 
located in this class DefaultDependencyResolver:

at the following method:


     private Set<Artifact> resolveTransitively(
final Set<Artifact> dependencyArtifacts,
final List<ArtifactRepository> repos,
final ResolutionManagementInfo info,
final AssemblerConfigurationSource configSource )
  throws DependencyResolutionException
     {
         final MavenProject project = configSource.getProject();

         final ArtifactFilter filter = info.getScopeFilter();

         ArtifactResolutionRequest req = new ArtifactResolutionRequest();
         req.setLocalRepository( configSource.getLocalRepository() );
         req.setResolveRoot( false );
         req.setRemoteRepositories( repos );
         req.setResolveTransitively( true );
         req.setArtifact( project.getArtifact() );
         req.setArtifactDependencies( dependencyArtifacts );
         req.setManagedVersionMap( project.getManagedVersionMap() );
         req.setCollectionFilter( filter );
         req.setOffline( configSource.getMavenSession().isOffline() );
         req.setForceUpdate( 
configSource.getMavenSession().getRequest().isUpdateSnapshots() );
         req.setServers( 
configSource.getMavenSession().getRequest().getServers() );
         req.setMirrors( 
configSource.getMavenSession().getRequest().getMirrors() );
         req.setProxies( 
configSource.getMavenSession().getRequest().getProxies() );

         ArtifactResolutionResult result;

         result = resolver.resolve( req );
         if ( result.hasExceptions() )
         {
             throw new DependencyResolutionException( "Failed to resolve 
dependencies for assembly: ",
 
result.getExceptions().get( 0 ) );
         }

         FilterUtils.reportFilteringStatistics( Collections.singleton( 
filter ), getLogger() );

         return result.getArtifacts();
     }



And the identified line is:

         result = resolver.resolve( req );

which fails to find the appropriate dependencies...or better the wrong 
version of the dependencies....


So I'm not sure at the moment if this is based on Maven 2 compatibility 
of maven-assembly-plugin or if there is an other issue in there or I'm 
just simply wrong...

WDYT ?


Kind regards
Karl Heinz Marbaise



On 8/23/15 5:16 PM, Karl Heinz Marbaise wrote:
> Hi,
>
> I have test project where i defined the pom like this:
>
> ...
>    <modelVersion>4.0.0</modelVersion>
>
>    <groupId>com.soebes.examples.j2ee</groupId>
>    <artifactId>parent</artifactId>
>    <version>${revision}</version>
>    <packaging>pom</packaging>
>
> If i define the revision on command line like this.
>
> mvn -Drevision=1.0-SNAPSHOT clean package
>
> everything fine...
>
> But now i want to make the usage a bit more convenient so i added the
> following to my pom:
>
>
>    <properties>
>      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>      <revision>1.0-SNAPSHOT</revision>
>    </properties>
>
> to have a default for revision which works fine now...
>
> But if i would like to overwrite the property from command line like this:
>
> mvn -Drevision=1.0 clean package
>
> the build failes in the following location:
>
> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (assemblies)
> on project assembly: Failed to create assembly: Unable to resolve
> dependencies for assembly 'archive': Failed to resolve dependencies for
> assembly: Unable to get dependency information for
> com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Failed to
> process POM for
> com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT: Non-resolvable
> parent POM for
> com.soebes.examples.j2ee:service-client:[unknown-version]: Failure to
> find com.soebes.examples.j2ee:parent:pom:${revision} in
> http://localhost:8081/nexus/content/groups/public was cached in the
> local repository, resolution will not be reattempted until the update
> interval of nexus has elapsed or updates are forced
> [ERROR] com.soebes.examples.j2ee:service-client:jar:1.0-SNAPSHOT
>
> The project is available on github
> (https://github.com/khmarbaise/javaee/tree/mvn321)....
>
> So the question which is coming up...is this based on Maven core or is
> this based on maven-assembly-plugin ?
>
> Kind regards
> Karl Heinz Marbaise

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