首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从maven汇编插件中排除依赖项: jar-with- dependencies?

如何从maven汇编插件中排除依赖项: jar-with- dependencies?
EN

Stack Overflow用户
提问于 2011-06-02 10:51:37
回答 3查看 38.3K关注 0票数 37

Maven的组装插件支持创建一个大jar,其中包含descriptorRef jar-with-dependencies的所有依赖项。

如何排除其中的一些依赖关系?它似乎没有这样的配置?有没有其他的解决方案?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-06-02 12:49:55

example指明了一种实现此目的的方法:

代码语言:javascript
复制
 <dependencySets>
    <dependencySet>
      ....
      <excludes>
        <exclude>commons-lang:commons-lang</exclude>
        <exclude>log4j:log4j</exclude>
      </excludes>
    </dependencySet>
    ....
  </dependencySets>

本质上,我们将使用dependencySet中提供的excludes选项。

另请参阅:https://maven.apache.org/plugins/maven-assembly-plugin/assembly-component.html

票数 4
EN

Stack Overflow用户

发布于 2015-03-29 21:28:06

<scope>provided</scope>添加到不希望包含在带有依赖项的jar中的依赖项中,例如

代码语言:javascript
复制
    <dependency>
      <groupId>storm</groupId>
      <artifactId>storm</artifactId>
      <version>0.6.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
票数 42
EN

Stack Overflow用户

发布于 2017-12-18 23:29:19

您应该使用dependencySet中提供的excludes选项。

如下所示:

pom.xml中的示例

代码语言:javascript
复制
...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <finalName>../final/${project.artifactId}</finalName>
          <archive>
            <manifest>
              <addClasspath>false</addClasspath>
              <mainClass>com.entrerprise.App</mainClass>
            </manifest>
          </archive>
          <descriptors>
            <descriptor>src/main/resources/jar-with-deps-with-exclude.xml</descriptor>
          </descriptors>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
...

现在在您的新文件jar-with-deps-with-exclude.xml ( dependencySet所在的位置)中:

代码语言:javascript
复制
 <?xml version="1.0" encoding="UTF-8"?>
    <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
        <id>jar-with-dependencies-and-exclude-classes</id>
        <formats>
          <format>jar</format>
        </formats>
        <includeBaseDirectory>false</includeBaseDirectory>
        <dependencySets>
          <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>false</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
            <excludes>
              <exclude>junit:junit</exclude>
              <exclude>commons-cli:commons-cli</exclude>
              <exclude>org.apache.maven.wagon:wagon-ssh</exclude>
            </excludes>
           </dependencySet>
        </dependencySets>
        <fileSets>
          <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>${project.build.outputDirectory}</directory>
          </fileSet>
        </fileSets>
      </assembly>

就这样。

票数 23
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6209903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档