Maven解压传递依赖性' JAR到一个文件夹

时间:2016-04-18 14:31:51

标签: maven dependencies

我的私有存储库com.test.Parentcom.test.Child中有两个maven工件。 Child取决于Parent

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

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

我想要的是调用,例如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的POM文件包含:

com.test.Child

您是否看到设置有任何问题?最后的结果是开发人员可以只下载一个pom.xml,运行<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> ,所有依赖项将自动下载并解压缩到某个结构。

由于

修改 当我删除本地Maven存储库并运行此pom时,会下载mvn <something>Child。因此依赖性存在,但Parent目标未获取Parent

1 个答案:

答案 0 :(得分:0)

我通过将<dependencies>块移到<plugins>之外来解决了这个问题。所以最终的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>

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

相关问题