提供的 Maven 范围和可传递的依赖项

Rav*_*avi 11 maven

我对其中一个 jar 有依赖性,并且我已将其标记为在 pom xml 中提供。似乎只有一些传递依赖 jar 被标记为提供并且没有与 war 一起打包,但其他的仍然是编译和打包的范围。

pom xml 中的依赖:

<dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-ftp</artifactId>
            <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

依赖树:

[INFO] +- org.apache.camel:camel-ftp:jar:2.17.0.redhat-630262:provided
[INFO] |  +- com.jcraft:jsch:jar:0.1.54:provided
[INFO] |  +- commons-net:commons-net:jar:3.3.0.redhat-3:provided
[INFO] |  +- com.sun.xml.bind:jaxb-core:jar:2.2.11:compile
[INFO] |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.11.redhat-2:compile
[INFO] +- org.apache.camel:camel-csv:jar:2.17.0.redhat-630262:provided
Run Code Online (Sandbox Code Playgroud)

插件版本详情:

<maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cdi.api.version>1.2.0.redhat-2</cdi.api.version>
        <javax.inject.version>1.0.0.redhat-6</javax.inject.version>
        <sonar.host.url>http://vfrde2srta0401.agcs.biz:9000</sonar.host.url>
        <xerces.version>2.11.0-22</xerces.version>
        <xmlunit.version>1.6</xmlunit.version>
        <maven.compilerplugin.version>3.7.0</maven.compilerplugin.version>
        <maven.releaseplugin.version>2.5.3</maven.releaseplugin.version>
        <maven.warplugin.version>3.2.0</maven.warplugin.version>
        <maven.jarplugin.version>3.0.2</maven.jarplugin.version>
        <maven.surefireplugin.version>2.20.1</maven.surefireplugin.version>
        <maven.coberturaplugin.version>2.7</maven.coberturaplugin.version>
Run Code Online (Sandbox Code Playgroud)

Pie*_* B. 7

根据Maven 文档(见表),如果您定义具有范围的依赖项provided,传递依赖项将具有以下最终范围,具体取决于其原始范围:

  • 编译 > 提供
  • 提供 >省略
  • 运行时 > 提供
  • 测试 >省略

然后应该考虑compile您的依赖项的传递依赖项。providedprovided


gjo*_*anv 7

正如一些人已经指出的那样,provided作用域依赖项的传递依赖项应该provided在您的项目中获得作用域。但是,如果作用域中有其他compile具有相同传递依赖项的依赖项,则可以将作用域更改为编译。在你的情况下,这两个:

[INFO] |  +- com.sun.xml.bind:jaxb-core:jar:2.2.11:compile
[INFO] |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.11.redhat-2:compile
Run Code Online (Sandbox Code Playgroud)

可能会被你的 pom 中的另一个依赖项传递进来,而不是camel-ftp. 您需要运行mvn dependency:tree -Dverbose以了解为什么这两个将其范围更新为compile.