【问题标题】:Force Maven 3 to copy 'provided' dependencies强制 Maven 3 复制“提供的”依赖项
【发布时间】:2013-04-18 23:54:58
【问题描述】:

我使用 copy-dependencies 目标来复制当前工件的依赖项。 但它不会复制范围为“提供”的依赖项。 如何解决?

xml配置是标准的:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>lib</outputDirectory>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <excludeArtifactIds>project-services</excludeArtifactIds>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>project-web</finalName>
</build>

我为什么要这样做? 因为我必须同时支持 ant 和 maven 构建工作。 因此,我想通过运行 mvn install -o 将所有依赖项复制到单独的目录中。在 Ant build.xml 中,我将该目录的路径包含为类路径。之后 Ant 构建 ear 文件并包含整个 lib 目录,没有系统 tools.jar 和其他“提供”的 jar。 Apache Maven 的版本是 3.0.3

【问题讨论】:

  • 你在运行哪个 Maven 命令?
  • 您为什么要这样做?具有 scope=provided 的依赖项以这种方式标记,因为它们已经存在于目标环境中。为什么要复制它们?
  • 如果您需要复制它们,为什么要标记它们提供?
  • 我更新了问题。 Maven 3.

标签: java maven


【解决方案1】:

正如插件所记录的,使用 includeScope:

http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html#includeScope

编辑

我为什么要这样做?因为我要同时支持ant和maven 构建工作。

考虑使用 Ivy 来管理与 Ant 的依赖关系: http://ant.apache.org/ivy/

这里有一篇文章如何配置 Ivy 以连接到 Nexus:

https://support.sonatype.com/entries/21627528-how-do-i-configure-my-ivy-build-to-download-artifacts-from-nexus

【讨论】:

  • 但是文档也说 Scope to include。 Empty 字符串表示所有范围(默认)。 因此,不必使用includeScope
  • 真的,我刚刚看到了。
猜你喜欢
  • 1970-01-01
  • 2013-11-25
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 2014-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多