Index: /home/herve/projet/workspace/maven-ant-tasks/sample.build.xml
===================================================================
--- /home/herve/projet/workspace/maven-ant-tasks/sample.build.xml	(revision 524294)
+++ /home/herve/projet/workspace/maven-ant-tasks/sample.build.xml	(working copy)
@@ -94,7 +94,7 @@
       <fileset refid="my.dependency.fileset"/>
     </copy>
 
-    <artifact:dependencies filesetId="my.compile.dependency.fileset" useScope="compile">
+    <artifact:dependencies filesetId="my.compile.dependency.fileset" useScope="compile" versionsPropertyName="my.compile.dependency.versions">
       <pom refid="maven.project"/>
     </artifact:dependencies>
 
@@ -100,6 +100,7 @@
 
     <copy todir="target/my-compile-dependencies">
       <fileset refid="my.compile.dependency.fileset"/>
+      <mapper classpathref="maven.classpath" classname="org.apache.maven.artifact.ant.VersionMapper" from="${my.compile.dependency.versions}" />
     </copy>
 
     <copy todir="target/my-compile-dependencies/WEB-INF/lib">
@@ -104,7 +105,7 @@
 
     <copy todir="target/my-compile-dependencies/WEB-INF/lib">
       <fileset refid="my.compile.dependency.fileset"/>
-      <mapper type="flatten" />
+      <mapper classpathref="maven.classpath" classname="org.apache.maven.artifact.ant.VersionMapper" from="${my.compile.dependency.versions}" to="flatten" />
     </copy>
 
     <antcall target="test-deploy" />
@@ -212,7 +213,7 @@
     <artifact:deploy file="sample-build-test.pom">
       <pom file="sample-build-test.pom" />
       <remoteRepository refid="deploy.repository" />
-    </artifact:deploy>  
+    </artifact:deploy>
   </target>
 </project>
 
Index: /home/herve/projet/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
===================================================================
--- /home/herve/projet/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java	(revision 524294)
+++ /home/herve/projet/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java	(working copy)
@@ -39,9 +39,12 @@
 import org.apache.tools.ant.types.FileList;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Path;
+import org.codehaus.plexus.util.StringUtils;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -64,6 +67,8 @@
 
     private String filesetId;
 
+    private String versionsPropertyName;
+
     private String useScope;
 
     private String type;
@@ -193,6 +198,8 @@
         FileSet fileSet = new FileSet();
         fileSet.setDir( fileList.getDir( getProject() ) );
 
+        Set versions = new HashSet();
+
         if ( result.getArtifacts().isEmpty() )
         {
             fileSet.createExclude().setName( "**/**" );
@@ -210,6 +217,8 @@
                 fileList.addConfiguredFile( file );
 
                 fileSet.createInclude().setName( filename );
+
+                versions.add( artifact.getBaseVersion() );
             }
         }
 
@@ -224,6 +233,11 @@
         {
             getProject().addReference( filesetId, fileSet );
         }
+
+        if ( versionsPropertyName != null ) {
+            String versionsValue = StringUtils.join( versions.iterator(), File.pathSeparator );
+            getProject().setNewProperty( versionsPropertyName, versionsValue );
+        }
     }
 
     private List createRemoteArtifactRepositories( List remoteRepositories )
@@ -276,6 +290,16 @@
         this.filesetId = filesetId;
     }
 
+    public String getVersionsPropertyName()
+    {
+        return versionsPropertyName;
+    }
+
+    public void setVersionsPropertyName( String versionsPropertyName )
+    {
+        this.versionsPropertyName = versionsPropertyName;
+    }
+
     public void setVerbose( boolean verbose )
     {
         this.verbose = verbose;
Index: /home/herve/projet/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java
===================================================================
--- /home/herve/projet/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java	(revision 0)
+++ /home/herve/projet/workspace/maven-ant-tasks/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java	(revision 0)
@@ -0,0 +1,85 @@
+package org.apache.maven.artifact.ant;
+
+/*
+ * Copyright 2001-2007 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tools.ant.util.FileNameMapper;
+import org.codehaus.plexus.util.StringUtils;
+
+public class VersionMapper implements FileNameMapper, Comparator
+{
+    private List versions;
+
+    private String to;
+
+    public String[] mapFileName( String sourceFileName )
+    {
+        String originalFileName = new java.io.File(sourceFileName).getName();
+        for ( Iterator iter = versions.iterator(); iter.hasNext(); )
+        {
+            String version = (String) iter.next();
+            int index = originalFileName.indexOf( version );
+            if ( index >= 0)
+            {
+                // remove version in artifactId-version(-classifier).type
+                String baseFilename = originalFileName.substring( 0, index - 1 );
+                String extension = originalFileName.substring( index + version.length() );
+                String path = sourceFileName.substring( 0, sourceFileName.length() - originalFileName.length() );
+                if ( "flatten".equals( to ) )
+                {
+                    path = "";
+                }
+                return new String[] { path + baseFilename + extension };
+            }
+        }
+        return new String[] { sourceFileName };
+    }
+
+    /**
+     * Set the versions identifiers that this mapper can remove from filename. The value separator
+     * used is path separator.
+     */
+    public void setFrom( String from )
+    {
+        String[] split = StringUtils.split( from, File.pathSeparator );
+        // sort, from lengthiest to smallest
+        Arrays.sort( split, this );
+        versions = Arrays.asList( split );
+    }
+
+    /**
+     * By default, only filename is changed, but if this attribute is set to <code>flatten</code>,
+     * directory is removed.
+     */
+    public void setTo( String to )
+    {
+        this.to = to;
+    }
+
+    public int compare( Object o1, Object o2 )
+    {
+        String s1 = (String)o1;
+        String s2 = (String)o2;
+        int lengthDiff = s2.length() - s1.length();
+        return ( lengthDiff != 0 ) ? lengthDiff : s1.compareTo( s2 );
+    }
+}

