![](/img/trans.png)
[英]Exception while trying to deploy Maven build JAR to github package registry
[英]Package maven app into a single jar - with an exception
我的應用程序中有一些依賴項,我希望在構建過程中將所有依賴項打包到一個jar中,除了單個依賴項(團隊的實用程序jar)外。 發現了如何使用maven-assembly-plugin構建到單個jar,不知道如何排除特定的依賴關系。
這是相關的pom.xml文件:
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file://repository_path</url>
</repository>
</repositories>
....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.10</source>
<target>1.10</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>app-name</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.appname.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>
...
<dependencies>
<dependency>
<groupId>com.company.utils</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
可能包含和排除工件將為您提供幫助。
更具體地說,您需要創建自己的assembly.xml
文件:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>jar-with-dependencies-exclude</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>com.fasterxml.jackson.datatype:jackson-datatype-jsr310</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
然后更改您的插件配置以使用此文件:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>app-name</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.appname.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.