Maven系统作用域导致忽略其他依赖项

nle07wnf  于 2024-01-06  发布在  Maven
关注(0)|答案(1)|浏览(309)

我修改了我的pom.xml文件,将一个系统作用域依赖项添加到一个公共库中,我在多个项目中使用该公共库作为依赖项。在添加系统作用域依赖项之前,我能够编译和安装公共库,并且它的所有依赖项都可以在包括公共库作为依赖项的项目中使用。在添加系统作用域依赖项之后,公共库的其他依赖项在子项目中都不可用。
公共库pom.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.conceptualsystems</groupId>
  7. <artifactId>common</artifactId>
  8. <version>3.3</version>
  9. <properties>
  10. <maven.compiler.source>8</maven.compiler.source>
  11. <maven.compiler.target>8</maven.compiler.target>
  12. </properties>
  13. <dependencies>
  14. <dependency>
  15. <groupId>javax.mail</groupId>
  16. <artifactId>mail</artifactId>
  17. <version>1.5.0-b01</version>
  18. </dependency>
  19. <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
  20. <!-- <dependency>-->
  21. <!-- <groupId>org.junit.jupiter</groupId>-->
  22. <!-- <artifactId>junit-jupiter</artifactId>-->
  23. <!-- <version>5.9.3</version>-->
  24. <!-- <scope>test</scope>-->
  25. <!-- </dependency>-->
  26. <dependency>
  27. <groupId>org.ini4j</groupId>
  28. <artifactId>ini4j</artifactId>
  29. <version>0.5.4</version>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.slf4j</groupId>
  33. <artifactId>slf4j-api</artifactId>
  34. <version>2.0.6</version>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.json</groupId>
  38. <artifactId>json</artifactId>
  39. <version>20180813</version>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.apache.pdfbox</groupId>
  43. <artifactId>pdfbox</artifactId>
  44. <version>2.0.19</version>
  45. </dependency>
  46. <dependency>
  47. <groupId>com.itextpdf</groupId>
  48. <artifactId>html2pdf</artifactId>
  49. <version>3.0.1</version>
  50. </dependency>
  51. <dependency>
  52. <groupId>javax.mail</groupId>
  53. <artifactId>mail</artifactId>
  54. <version>1.5.0-b01</version>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.apache.httpcomponents</groupId>
  58. <artifactId>httpcore</artifactId>
  59. <version>4.1.1</version>
  60. </dependency>
  61. <dependency>
  62. <groupId>org.apache.httpcomponents</groupId>
  63. <artifactId>httpclient</artifactId>
  64. <version>4.1.1</version>
  65. </dependency>
  66. <dependency>
  67. <groupId>org.apache.httpcomponents</groupId>
  68. <artifactId>httpmime</artifactId>
  69. <version>4.1.1</version>
  70. </dependency>
  71. <dependency>
  72. <groupId>commons-net</groupId>
  73. <artifactId>commons-net</artifactId>
  74. <version>3.8.0</version>
  75. </dependency>
  76. <dependency>
  77. <groupId>gnu.io</groupId>
  78. <artifactId>rxtx</artifactId>
  79. <version>2.2pre2</version>
  80. <scope>system</scope>
  81. <systemPath>${project.basedir}/lib/RXTXcomm.jar</systemPath>
  82. </dependencies>
  83. </project>

字符串
依赖于这个库的项目应该有它所有的依赖项。如果我在最后删除gnu.io.rxtx依赖项,其他的依赖项在子项目中是可用的。为什么仅仅通过从本地目录中包含一个.jar依赖项,行为就会发生如此大的变化?
期望的行为:保留原始行为,并包括新的依赖项,以及在依赖项目中可用的其他依赖项。

mlnl4t2r

mlnl4t2r1#

对于普通依赖项,maven可以访问

  • 指向任何子依赖项的pom
  • 包含二进制类文件的jar文件

还有其他文物,如

  • Javadocs
  • 来源
  • 校验和

例如:查看可用于spring-core依赖项here的工件
当你有一个来自<systemPath>的依赖时,maven不能访问pom或任何其他工件。它只有一个对jar的引用,所以不能导入任何子依赖。

相关问题