我设法指示maven创建一个包含所有依赖项的jar。当我运行'mvn package'时,它将生成两个文件:elvt-1.0.jar和elvt-1.0-jar-with-dependencies.jar。
但是,我不关心没有依赖关系的jar,我希望依赖关系的jar的名称是elvt-1.0.jar。我设法通过添加
来做到这一点<appendAssemblyId>false</appendAssemblyId>
到maven-assembly-plugin工件的配置部分。这会产生两个警告:
[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing.
Instead of attaching the assembly file: /home/user/workspace/elvt/target/elvt-1.0.jar, it will become the file for main project artifact.
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[WARNING] Replacing pre-existing project main-artifact file: /home/user/workspace/elvt/target/elvt-1.0.jar
with assembly file: /home/user/workspace/elvt/target/elvt-1.0.jar
如果我理解正确,他们都警告我不要依赖覆盖jar。如何告诉maven不要生成没有依赖关系的jar?
供参考,这就是我的pom.xml:
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Program</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>elvt</artifactId>
<version>1.0</version>
</project>