【问题标题】:Maven unpack transitive dependencies' JAR to a folderMaven 将传递依赖项的 JAR 解包到一个文件夹
【发布时间】:2016-04-18 22:59:14
【问题描述】:

我的私有存储库中有两个 Maven 工件,com.test.Parentcom.test.ChildChild 依赖于 Parent

我希望 Maven 做的唯一一件事就是下载 Child jar 及其依赖的所有内容,然后将其解压缩到一个目录中。

我能够通过调用mvn clean dependency:unpack 来组合一个pom.xml 来下载Child,但是为了下载传递依赖项,我必须手动将它包含在pom 中。

我想要的是调用,例如maven initialize,我需要的依赖项将被下载。我现在拥有的是这样的:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                      <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.test</groupId>
                                <artifactId>Child</artifactId>
                                <version>1.2.3</version>
                                <type>jar</type>
                                <includes>**</includes>
                                <excludes>META-INF/**</excludes>
                                <outputDirectory>somepath/sources</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <excludeTransitive>false</excludeTransitive>
                        <includes>**</includes>
                        <outputDirectory>somepath/depend</outputDirectory>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.test</groupId>
                    <artifactId>Child</artifactId>
                    <version>1.2.3</version>
                    <type>jar</type>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>

但是,当我运行mvn clean initialize 时,只有子文件被下载并解压。

com.test.Child 的 POM 文件包含以下内容:

<groupId>com.test</groupId>
<artifactId>Child</artifactId>
<version>1.2.3</version>

<dependencies>
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>Parent</artifactId>
        <version>7.8.9</version>
    </dependency>
</dependencies>

您是否发现设置有任何问题?最终结果是开发者只需下载一个 pom.xml,运行mvn &lt;something&gt;,所有依赖项都会自动下载并解压到一定的结构。

谢谢

编辑: 当我删除本地 Maven 存储库并运行这个 pom 时,ChildParent 都会被下载。所以存在依赖关系,但Parent 没有被unpack-dependencies 目标拾取。

【问题讨论】:

    标签: maven dependencies


    【解决方案1】:

    我通过将&lt;dependencies&gt; 块移到&lt;plugins&gt; 之外解决了这个问题。所以最终的POM结构是:

    <project>
      <build>
        <plugins>
          <plugin>
            ...
          </plugin>
        </plugins>
      </build>
    
      <dependencies>
          <dependency>
              <groupId>com.test</groupId>
              <artifactId>Child</artifactId>
              <version>1.2.3</version>
          </dependency>
      </dependencies>
    </project>
    

    但如果有人可以向我解释为什么这会有所帮助,那将不胜感激。

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 2019-09-03
      • 1970-01-01
      • 2020-09-21
      • 2023-03-30
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多