我试图建立一个胖罐子在其他一些地方使用它。
我用maven assembly plugin
为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
在我依赖我有一个本地的jar依赖,这是我无法拒绝:
<dependency>
<groupId>com.example</groupId>
<artifactId>library</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
</dependency>
但这个罐子是对包括我与mvn package
创建最终的脂肪罐子。
什么是包括我的地方罐子脂肪罐子作为一个依赖的最好方法?
UPD。 还有一些相关的问题,但他们没有完全回答这个问题: add jar to the maven local repository before build maven-assembly-plugin doesn't add dependencies with system scope
更容易地使用遮阳插件:
父项目:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greg</groupId>
<artifactId>fat-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>library-jar</module>
<module>final-jar</module>
</modules>
</project>
库项目:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>fat-jar</artifactId>
<groupId>com.greg</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>library-jar</artifactId>
<dependencies>
....
</dependencies>
<build>
</build>
</project>
最终罐子依赖于库中,同一父下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>fat-jar</artifactId>
<groupId>com.greg</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>final-jar</artifactId>
<dependencies>
<dependency>
<groupId>com.greg</groupId>
<artifactId>library-jar</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.greg.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>