[英]How can I use previously built jars in a multi-module maven project?
ModuleA
src
pom.xml
target
ModuleA-with-dependencies-shaded.jar (version 4.1 of lucene relocated)
ModuleB
src
pom.xml
target
ModuleB-with-dependencies.jar (version 7.5.0 of lucene)
ModuleDist
assembly
all.xml
pom.xml (shaded plugin for jar + assembly for Docker)
dist pom 插件配置如下:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<shadedClassifierName>all</shadedClassifierName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<!--remove models from jar see mitie -->
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>.dat</resource>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<id>make-dist</id>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/all.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
和程序集 all.xml :
<assembly>
<id>all</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/docker</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
由於ModuleA
對lucene 4.1
具有傳遞依賴性(但已重新定位,因此不會與 moduleB 發生沖突)而ModuleB
對lucene 7.5.0
具有傳遞依賴性,因此我想使用先前構建和着色的ModuleA
jar在Maven的陰影插件ModuleDist
(因為如果我在搬遷Lucene的ModuleDist
它是所有搬遷的lucene類)。
我怎么能那樣做?
或者有另一種方法嗎?
要將所有運行時依賴項的 jar 添加到程序集中,請添加如下內容:
<?xml version="1.0"?>
<assembly>
...
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
有關更多詳細信息,請查看程序集插件文檔。 可以在此處找到一個工作示例(未使用陰影)。
我的個人經驗是最好只有一個最終模塊來組裝所有東西。 這樣着色器就不必一遍又一遍地拆卸和組裝所有東西。
使用 Jackson 和 Log4j2 時,着色是一個大問題,因為它破壞了一些期望所有內容都在單獨的 jar 中的擴展查找機制。 我建議不要再使用它了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.