如何解压所有托管的Maven依赖项?

时间:2013-09-15 15:36:14

标签: java maven maven-dependency-plugin

我想启用我的Maven构建来获取所有源代码和JavaDoc jar并在多模块Maven项目中解压缩所有JavaDoc jar 一次

我在Maven依赖插件的帮助下管理,以获取每个子模块的所有源和JavaDoc jar。但我只需要一次解压缩而不是每个子模块。

最好的解决方案是能够解压缩项目父POM中指定的所有托管依赖项。知道如何实现这个目标吗?

这是我目前的解决方案:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>fetch-source</id>
      <goals>
        <goal>sources</goal>
      </goals>
    </execution>
    <execution>
      <id>fetch-doc</id>
      <goals>
        <goal>resolve</goal>
      </goals>
      <configuration>
        <classifier>javadoc</classifier>
      </configuration>
    </execution>
    <execution>
      <id>unpack-javadoc</id>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <configuration>
        <classifier>javadoc</classifier>
          <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
        <stripClassifier>true</stripClassifier>
      </configuration>
    </execution>
  </executions>
</plugin>

2 个答案:

答案 0 :(得分:0)

听起来你想利用<inherited/>元素/属性来执行插件。例如:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>fetch-source</id>
      <!-- Will prevent this plugin execution in child modules. -->
      <inherited>false</inherited>
      <goals>
        <goal>sources</goal>
      </goals>
    </execution>
  </executions>
</plugin>

答案 1 :(得分:0)

好的,我最终得到了这个档案:

<profile>
  <id>fetchdocandsource</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>fetch-source</id>
            <goals>
              <goal>sources</goal>
            </goals>
          </execution>
          <execution>
            <id>fetch-doc</id>
            <goals>
              <goal>resolve</goal>
            </goals>
            <configuration>
              <classifier>javadoc</classifier>
            </configuration>
          </execution>
          <execution>
            <id>unpack-javadoc</id>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <classifier>javadoc</classifier>
              <useRepositoryLayout>true</useRepositoryLayout>
              <outputDirectory>${env.HOME}/javadoc</outputDirectory>
              <stripClassifier>true</stripClassifier>
              <markersDirectory>${env.HOME}/javadoc/.markers</markersDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

在当前配置中,我能够获取所有源和JavaDoc jar并将所有JavaDoc文件存储在中央目录中。拥有标记文件的中心目录(请参阅<markersDirectory/>)可以防止dependnency插件针对相同或不同的项目多次解包相同的JavaDoc依赖项。