我有一个包含三个主要部分的Java项目:
net.code
xyz.code
xyz.code.api
我想创建两个Jars:一个用于所有内容,一个用于xyz.code.api
。第二个Jar还必须包含所有依赖项。
我有两个配置文件设置来执行此操作。第一个配置文件有效,但第二个配置文件不排除包。
<profile>
<id>all</id>
<build>
<resources>
<resource>
<directory>src/res</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>xyz.code.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>api</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>api</shadedClassifierName>
<excludes>
<exclude>**/net/code/*</exclude>
<exclude>**/xyz/code/*</exclude>
</excludes>
<includes>
<include>**/xyz/code/api/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
创建了两个Jars,但它们都包含项目中的所有内容。
答案 0 :(得分:2)
如果jar共享相同的依赖项(因此可以使用相同的pom),您可以考虑使用maven ejb插件:
http://maven.apache.org/plugins/maven-ejb-plugin/examples/generating-ejb-client.html
否则,应考虑将项目拆分为两个模块,因为从同一项目中创建两个工件是“反Maven”。有解决方法,但它们更复杂。