我正在使用 Maven 程序集插件,以便我可以包含特定的依赖项(基本上我想
在我的 jar 文件中包含特定的传递依赖项)类。这是来自 pom.xml
-
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
看起来可以通过链接http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html 但是只要提到下面的代码片段就包含两种类型的依赖项 com.companyA.* 和 com.companyB.* ,除了 我不想排除所有其他依赖项
<dependencySets>
<dependencySet>
<includes>
<include>com.companyA.*</include>
<include>com.companyB.*</include>
</includes>
</dependencySet>
</dependencySets>
但是pom.xml
显示依赖集内容无效。我不知道如何实现这里的目标?
最佳答案
我想你和我有同样的问题。这里你只能在 pom.xml 中进行部分配置,如下所示:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<outputDirectory>d:/temp/stock</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
但是您可以在 assembly.xml 中配置大部分程序集配置,如下所示:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>/</outputDirectory>
<includes>
<include>org.tkxing.stock:org.tkxing.stock.test</include>
</includes>
</dependencySet>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib/</outputDirectory>
<excludes>
<exclude>org.springframework:spring-beans</exclude>
<exclude>org.springframework:spring-asm</exclude>
<exclude>org.springframework:spring-core</exclude>
<exclude>org.springframework:spring-aop</exclude>
<exclude>org.springframework:spring-context</exclude>
<exclude>org.springframework:spring-expression</exclude>
<exclude>org.springframework:spring-jms</exclude>
<exclude>org.springframework:spring-tx</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>conf</directory>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<directory>bundles</directory>
<outputDirectory>bundles</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<source>log4j.xml</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
希望这可以帮助其他人
关于java - 使用 Maven 程序集插件包含特定依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28221899/