答案 0 :(得分:1)
我使用了sonatype jarjar maven插件来自动创建重命名为不同包的依赖类的副本。
这为您的库提供了其依赖项的私有副本,从而防止版本与可能部署的任何其他库发生冲突。
请记住,某些软件可能具有许可条件,阻止您更改其副本。
例如,以下规则对创建Apache commons-lang3的私有副本。 Apache commons-lang通常部署在名为org.apache.commons.lang3
的包中,但是在这里我在包com.lexicalscope.fluentreflection.internal.lang3
中创建了它的副本。该插件会自动修复我的库使用Apache commons-lang3链接到副本的所有位置。
<rule>
<pattern>org.apache.commons.lang3.**.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.lang3.@1.$@2</result>
</rule>
<rule>
<pattern>org.apache.commons.lang3.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.lang3.$@1</result>
</rule>
您可以使用相同的方法使用自己的依赖项的私有副本重新打包第三方库。
以下是maven构建配置的完整示例:
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>jarjar-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>jarjar-classes</id>
<phase>process-test-classes</phase>
<goals>
<goal>jarjar</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<input>{classes}</input>
</configuration>
</execution>
<execution>
<id>jarjar-testclasses</id>
<phase>process-test-classes</phase>
<goals>
<goal>jarjar</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<input>{test-classes}</input>
</configuration>
</execution>
</executions>
<configuration>
<overwrite>true</overwrite>
<includes>
<include>com.google.inject:guice</include>
<include>com.googlecode.lambdaj:lambdaj</include>
<include>org.apache.commons:commons-lang3</include>
<include>com.google.guava:guava</include>
</includes>
<rules>
<rule>
<pattern>com.google.common.**.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.guava.@1.$@2</result>
</rule>
<rule>
<pattern>com.google.common.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.guava.$@1</result>
</rule>
<rule>
<pattern>com.google.inject.**.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.guice.@1.$@2</result>
</rule>
<rule>
<pattern>com.google.inject.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.guice.$@1</result>
</rule>
<rule>
<pattern>ch.lambdaj.**.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.lamdaj.@1.$@2</result>
</rule>
<rule>
<pattern>ch.lambdaj.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.lamdaj.$@1</result>
</rule>
<rule>
<pattern>org.apache.commons.lang3.**.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.lang3.@1.$@2</result>
</rule>
<rule>
<pattern>org.apache.commons.lang3.*</pattern>
<result>com.lexicalscope.fluentreflection.internal.lang3.$@1</result>
</rule>
</rules>
</configuration>
</plugin>
答案 1 :(得分:0)
Project Jigsaw即将出现,将成为 Java 9 的一部分。