我在maven中有一些模块,我想构建一个模块的jar,它只依赖于其他模块。
如何在jar中包含两个模块?
编辑:
我有以下模块:
myproject-core/
myproject-api/
myproject-dependencie/
myproject-api-web/
我想用myproject-dependencie在myproject-api中构建一个jar。我在myproject-api中有更多依赖项,我只需要在这个jar中使用myproject-api和myproject-dependencie。
谢谢!
答案 0 :(得分:1)
我想maven-shade-plugin将是你的朋友:
https://maven.apache.org/plugins/maven-shade-plugin/
在你的插件部分,例如:
...
<properties>
<shade-main-class>{your-main-class}</shade-main-class>
</properties>
...
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>com/yourcompany/**</include>
</includes>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${shade-main-class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
...