首页 > 解决方案 > 使用 maven 插件下载具有依赖关系的特定 jar

问题描述

我需要下载一组具有依赖关系的特定 jar 并将其放在单独的文件夹中。下面是我来自 pom.xml 的代码

<profile>
  <id>copy-dep</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.8</version>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>org.springframework.data</groupId>
              <artifactId>spring-data-commons</artifactId>
              <version>xxx</version>
            </artifactItem>
            <artifactItem>
              <groupId>org.springframework.security.oauth</groupId>
              <artifactId>spring-security-oauth2</artifactId>
              <version>xxx</version>
            </artifactItem>
          </artifactItems>
          <outputDirectory>${project.build.directory}/libs</outputDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

当我使用以下命令时,只会下载特定的依赖项,而不是传递依赖项。如果我不能使用排除标签,也可以使用 artifactItem。

mvn dependency:copy -Pcopy-dep 

如果我使用mvn dependency:copy-dependencies它会在 pom.xml 中查找我不想要的所有依赖项。我尝试替换<artifactItems><dependencies>但也没有用,出现以下错误

Caused by: org.apache.maven.plugin.MojoFailureException: Either artifact or artifactItems is required 

有没有办法我可以获得所有选定的依赖项(具有传递依赖项)并排除一些依赖项?如果有更好的插件可以推荐。

标签: javamavenmaven-plugin

解决方案


推荐阅读