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>
5
  • can you share more of your pom.xml configuration? how are they copied to your lib folder? Commented Jun 15, 2016 at 14:40
  • Are you using maven-dependency-plugin:copy-dependencies goal? Commented Jun 15, 2016 at 14:42
  • What kind of project are you doing? WAR/EAR ? something different? Commented Jun 15, 2016 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: pastebin.com/WBuAcnzw Commented Jun 16, 2016 at 9:04
  • @dejvid please next time add the configuration directly (and from the start) to your question: that would simplify and speed-up feedbacks :) Commented Jun 16, 2016 at 11:50

1 Answer 1

7

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>
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't work in 2024 and 3.x plugin. Please use property: <mdep.stripVersion>true</mdep.stripVersion>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.