Maven - 添加jar-with-dependencies作为依赖项 [英] Maven - Add jar-with-dependencies as a dependency
问题描述
问题..
我想在与其依赖打包的Maven jar 上添加依赖项。
Question..
I'd like to add a dependency on a Maven jar packaged with it's dependencies.
详细信息..
我有一个多模块Maven项目,其中一个模块依赖于本机库等。作为它构建的一部分,它将它的依赖关系打包成 jar-with-dependencies
,如下所示:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
一切都很好,我建造时会得到两个罐子:
All good, I get two jars when I build:
seaniscool-0.0.1-SNAPSHOT.jar
seaniscool-0.0.1-SNAPSHOT-jar-with-dependencies.jar
但是,我想在同一个项目的另一个模块中使用这个工件。如果我只是将模块添加为依赖项,我将获得没有包含本机库的jar。
However, I'd like to use this artifact in another module of the same project. If I simply add the module as a dependency, I get the jar without the native libraries included.
我可以复制构建配置以在第二个模块中包含本机库另外,它不是很广泛,但不愿意。
I could duplicate the build configuration to include the native libraries in the 2nd module also, it's not very extensive, but would prefer not to.
任何想法如何添加 jar-with-dependencies
作为依赖,因此取决于所包含的库?
Any ideas how I can add the jar-with-dependencies
as a dependency and thus depend on the libraries included?
一些想法..
我知道我可以使用Maven可以引用的测试类构建一个单独的jar:
Some thoughts..
I know I can build a separate jar with test classes that Maven can reference:
在第一个模块中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
在第二个模块中:
<dependency>
<groupId>my.group.id</groupId>
<artifactId>my.artifact.id</artifactId>
<version>my.version</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
这个概念可以转移吗?
推荐答案
您可以使用 maven分类器执行此操作。使用类文件,因此maven模块可以从同一来源构建多个人工制品。示例是jdk1.6或1.7版本,甚至是maven可以构建的源代码和javadoc jars。
You can do this with a maven classifier. Classfiers are used so a maven module can build multiple artefacts from the same source. Examples are jdk1.6 or 1.7 version or even the source and javadoc jars maven can build.
所以试试这个:
<dependency>
<groupId>yourID</groupId>
<artifactId>seaniscool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
如果您想将您的类文件重命名为更好的名称,例如withNative或者完整或其他任何看起来在 maven shade插件中,它还可以构建具有依赖关系的jar,但允许更多控制。
If you want to rename your classfier to a better name like withNative or complete or anything else have a look at the maven shade plugin which can also build jars with dependencies but allows some more control.
这篇关于Maven - 添加jar-with-dependencies作为依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!