我有一个maven项目,应该生成几个二进制文件。其中一些有其他依赖关系,依赖关系可能从二进制到二进制不同。
问题是:如何在不包含每个依赖的情况下实现这一点,而只将必要的依赖包含在每个jar中?
目前我使用的程序集插件除了将每个依赖项放入每个jar之外。此外,它创建了我不需要的标准app1-snapshot jar。我怎么能摆脱它?
我的pom文件:
<?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>antlrtest</groupId>
<artifactId>app1</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>thf_test</id>
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>parsers.THF_test</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>bin/THF_test</finalName>
</configuration>
</execution>
<execution>
<id>hmf_test</id>
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>parsers.HMF_test</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>bin/HMF_test</finalName>
</configuration>
</execution>
<execution>
<id>HMF_to_THF</id>
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>transformation.HMF_to_THF</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>bin/HMF_to_THF</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!-- antlr -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5</version>
<configuration>
<arguments>
<argument>-package</argument>
<argument>parsers</argument>
</arguments>
</configuration>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
答案 0 :(得分:0)
正如https://stackoverflow.com/a/2426271/800413中所解释的那样,从同一个项目生成多个工件/二进制文件通常是一种不好的做法。
在您的情况下,为什么不让多个项目共享主代码库作为依赖项并生成所需的二进制文件,每个项目都有适当的库?