maven 下载依赖源码

最近在开发过程,发现java项目中的依赖包源码没有导入,因此debug的过程中,跟踪变量问题寸步难行。查看了相关的maven文档,常用的有如下三种方式来下载源码:

mvn 命令

下载源码时可以通过配置不同的参数来决定要不要下载java doc

# 只下载源码
mvn dependency:sources
# 只下载java doc
mvn dependency:resolve -Dclassifier=javadoc
# 源码和java doc都下载
mvn dependency:sources dependency:resolve -Dclassifier=javadoc

可以这么说,这是通过手动的方法下载源码,如果每个项目都要运行命令,还是有点麻烦的。因此可以看一下下面两种方法。

全局配置setting.xml

在~/m2/setting.xml中加入如下配置,这就可以保证使用此配置文件的项目都可以自动下载源码。

<settings>
    <!-- ... other settings omitted ... -->
    <profiles>
        <profile>
            <id>downloadSources</id>
            <properties>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </properties>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>downloadSources</activeProfile>
    </activeProfiles>
</settings>

使用maven-dependency-plugin

可以根据自己项目的需要配置加入插件,如果公司所有的项目都要下载源码,那么可以配置到parent pom.xml中。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.1.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>sources</goal>
                        <goal>resolve</goal>
                    </goals>
                    <configuration>
                        <classifier>javadoc</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当然,还有其他的方式,例如官网下载,然后放入repository中。或者在IDE上进行相关的配置等。最后希望本文能帮助大家,祝大家在IT之路上少走弯路,一路绿灯不堵车,测试一性通过,bug秒解!

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浦江之猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值