Sonar实践问题:指定第三方库目录

Sonar实践问题:指定第三方库目录

戈壁堂

2020.03.18 18:50:22字数 456阅读 1,022

理论已经由别人提出

added the target “dependency:copy-dependencies” as part of the maven execution. This copied all the dependencies to the right location, then I set the property “-Dsonar.java.libraries=target/dependency” in our case.

我的实践如下——

这个插件的官方maven-dependency-plugin 使用文档,根据样例如下——

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.1.2</version>
    <executions>
        <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
        <configuration>
            <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>false</overWriteSnapshots>
            <overWriteIfNewer>true</overWriteIfNewer>
        </configuration>
        </execution>
    </executions>
</plugin>

这样有两个问题:

  • 在多模块下自定义的这个outputDirectory目录是相对目录,会将依赖的jar包复制到子模块对应的目录下;
  • 根据这里的解决方案使用变量${session.executionRootDirectory}/target/,可以强制将依赖包都复制到固定目录,但只能在执行 mvn package阶段才生效

这样导致执行了接近全生命周期的任务。

这里涉及到phasegoal的概念区别:What are Maven goals and phases and what is their difference?

Life cycle is a sequence of named phases.
Phases executes sequentially. Executing a phase means executes all previous phases.

Plugin is a collection of goals also called MOJO (Maven Old Java Object).
Analogy : Plugin is a class and goals are methods within the class.

default Maven lifecycle bindings这里定义了在各个“阶段”(phase)都会执行哪些“目标动作”(goals)

mvn [plugin-name]:[goal-name] ,例如mvn dependency:copy-dependencies就是执行了插件maven-dependency-plugin定义的copy-dependencies动作。进一步,对应的configuration可以通过变量进行传参。

经验证,使用绝对路径地址指定outputDirectory的值是,可以将多模块的依赖统一复制到指定目录下。

所以,最终的解决方案为:

  1. 直接执行goal,mvn dependency:copy-dependencies -DoutputDirectory=absolute/path/to/lib/dir将所有的依赖复制到指定目录,
  2. 将上面的目录传递给sonar的sonar.java.libraries变量,例如 -Dsonar.java.libraries=absolute/path/to/lib/dir/*.jar

转自:Sonar实践问题:指定第三方库目录 - 简书 (jianshu.com)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值