如何将罐子源下载到Maven中的自定义位置? [英] How to download the souce of jars to custom location in maven?

查看:105
本文介绍了如何将罐子源下载到Maven中的自定义位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是如何获取pom.xml中提到的所有指定jar和与传递相关的jar的后续帖子? 除了我希望将依赖和传递依赖的jar的源下载到自定义提到的位置.

This is follow up post of How to get all the specified jars mentioned in the pom.xml and transitively dependent jars? Except that I am looking to download the source of the both dependent and transitively dependent jars to custom mentioned location.

我尝试了以下命令,但是没有用.

I have tried following command but it didn't works.

mvn dependency:sources -DoutputDirectory=.../

它没有用.

mvn dependency:sources dependency:copy-dependencies -DoutputDirectory=.../

它没有用.

推荐答案

通常可以通过Maven使用分类器,因此对于相同的Maven坐标(GAV,groupId,artifactId,版本),您可以拥有与同一内部版本(例如,默认应用程序/库jar,源jar,测试源jar,javadoc jar等),这也在另一个 Maven创建源插件.

The source jar is normally available via Maven using a classifier, so that for the same Maven coordinates (GAV, groupId, artifactId, version) you can have more than one artefact related to the same build (i.e. default application/library jar, sources jar, test sources jar, javadoc jar, etc.), as also explained in another SO answer. The standard classifier for sources is sources, created by the Maven Source Plugin.

复制依赖项可以配置为通过classifier选项获取特定分类器.

The copy-dependencies can be configured to fetch a certain classifier via the classifier option.

因此,在您的情况下,要将依赖项的源获取到外部文件夹,可以按以下方式调用命令:

So in your case, to get the sources of your dependencies to an external folder, you can invoke the command as following:

mvn dependency:copy-dependencies -DoutputDirectory=somewhere -Dclassifier=sources

请注意其他-Dclassifier=sources选项.

依赖项插件的官方文档,使用以下代码段:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>src-dependencies</id>
            <phase>package</phase>
            <goals>
              <!-- use copy-dependencies instead if you don't want to explode the sources -->
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <classifier>sources</classifier>
              <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
              <outputDirectory>${project.build.directory}/sources</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

请注意,尽管Maven不了解来源,但只了解人工制品.因此,如果无法通过其GAV + C获得来源(分类的)人工制品,则Maven将找到它,因此将不会下载任何来源.

Beware though that Maven doesn't know about sources, it only knows about artefacts. So if the sources (classified) artefact is not available via its GAV+C, Maven will find it and as such will not download any source.

这篇关于如何将罐子源下载到Maven中的自定义位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆