感谢单独的thread https://stackoverflow.com/questions/48715546/maven-how-to-specify-javac-plugin-argument-with-maven-compiler-plugin,我意识到我的项目的 uber-jar 有一个错误。我使用创建 uber-jarmaven-shade-plugin
因为我需要更高级的转换器功能来合并多个 ServiceLoader 定义。
所以,问题是我的项目有系统范围的编译时依赖tools.jar
, 定位tools.jar
在本地机器上相对于java.home
系统属性。错误是我没有意识到这种依赖性是:
- 泄漏到依赖减少
pom.xml
超级罐子的,和
- 更糟糕的是,模式
${java.home}
依赖关系定义中的内容被解析并硬编码到 uber-jar 的 POM 中。第二部分特别令人尴尬,因为它揭示了构建机器的 JDK 位置(参见第 50 行)here https://oss.sonatype.org/content/repositories/releases/systems/manifold/manifold-all/0.9-alpha/manifold-all-0.9-alpha.pom).
为了解决此问题,我有条件地禁用了创建依赖项的配置文件。以下所有详细信息均在<activation>
部分:
Before:
<profile>
<id>internal.tools-jar</id>
<activation>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
After:
<profile>
<id>internal.tools-jar</id>
<activation>
<jdk>1.8</jdk>
<file>
<missing>src/main/java/systems/manifold/Dummy.java</missing> <!-- this file is only present in the uber-jar module, therefore exclude if present -->
</file>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
所以,毕竟,我的问题是:这是防止这种系统范围的依赖关系泄漏到 uber-jar 的依赖关系减少的最好方法吗?pom.xml
?
提前致谢,
Kyle
2018年2月16日更新:
不幸的是,shade 插件中的以下配置并不能防止系统范围依赖项泄漏:
<artifactSet>
<excludes>
<exclude>*</exclude>
</excludes>
</artifactSet>
到阴影插件的配置,但解析的系统范围依赖关系仍然显示在 POM 中。令人费解!