7

I'd like to know if there is a way to remove version number from maven dependency.

Let's say for my project I'd like to fetch commons-lang3 3.4 using maven dependency plugin:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.4</version>
</dependency>

My pom configuration says, it is fetching dependencies to the ./lib directory inside of my project.
What I would like to achieve is remove on the fly version number from commons-lang3-3.4.jar. It would look like:

./lib/commons-lang3.jar

Question: Is there any way to do such thing?

Specifying finalName won't help here.

<build>
    <finalName>${project.name}-testing</finalName>
</build>

Below my existing configuration:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${dir.javaLibs}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
dejvid
  • 97
  • 1
  • 1
  • 5
  • can you share more of your `pom.xml` configuration? how are they copied to your `lib` folder? – A_Di-Matteo Jun 15 '16 at 14:40
  • Are you using [`maven-dependency-plugin:copy-dependencies`](http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html) goal? – Tunaki Jun 15 '16 at 14:42
  • What kind of project are you doing? WAR/EAR ? something different? – khmarbaise Jun 15 '16 at 14:49
  • It is something different. This is a "scripting" project, but I configured is as a maven project to fetch .jar dependencies used in the flow. I do use copy-dependencies goal. Please see part of my pom.xml file: http://pastebin.com/WBuAcnzw – dejvid Jun 16 '16 at 09:04
  • @dejvid please next time add the configuration directly (and from the start) to your question: that would simplify and speed-up feedbacks :) – A_Di-Matteo Jun 16 '16 at 11:50

1 Answers1

6

To remove the version from copied dependencies, you can use the stripVersion option of the maven-dependency-plugin:

Strip artifact version during copy

Which has default value to false.

Hence, given your existing configuration, here is the change:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${dir.javaLibs}</outputDirectory>

                            <!-- new configuration entry below-->
                            <stripVersion>true</stripVersion>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128