【问题标题】:Maven remove version from dependency jarMaven 从依赖 jar 中删除版本
【发布时间】:2016-10-16 17:41:17
【问题描述】:

我想知道是否有办法从 maven 依赖项中删除版本号。

假设对于我的项目,我想使用 maven 依赖插件获取 commons-lang3 3.4

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

我的 pom 配置显示,它正在将依赖项获取到我项目中的 ./lib 目录。
我想要实现的是从commons-lang3-3.4.jar 中即时删除版本号。它看起来像:

./lib/commons-lang3.jar

问题:有没有办法做到这一点?

在这里指定 finalName 无济于事。

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

在我现有的配置下:

<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>

【问题讨论】:

  • 您能分享更多您的pom.xml 配置吗?它们是如何复制到您的lib 文件夹中的?
  • 你在做什么项目?战争/耳朵?有什么不同?
  • 这是不同的东西。这是一个“脚本”项目,但我配置为一个 maven 项目来获取流程中使用的 .jar 依赖项。我确实使用了复制依赖目标。请查看我的 pom.xml 文件的一部分:pastebin.com/WBuAcnzw
  • @dejvid 请下次直接(从一开始)将配置添加到您的问题中:这将简化和加速反馈:)

标签: maven maven-3 pom.xml maven-dependency-plugin


【解决方案1】:

要从复制的依赖项中删除版本,您可以使用maven-dependency-pluginstripVersion 选项:

复制期间剥离工件版本

默认值为false

因此,鉴于您现有的配置,以下是更改:

<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>

【讨论】:

    猜你喜欢
    • 2015-03-07
    • 1970-01-01
    • 2019-10-06
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 2019-01-24
    • 2021-07-11
    相关资源
    最近更新 更多