maven:包括单个jar的选定依赖项

时间:2014-05-08 04:22:28

标签: java maven

我有一个maven模块,它依赖于另外两个模块

   <dependencies>
        <dependency>
            <groupId>com.org.me_services.federated_services</groupId>
            <artifactId>ifs</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.org.me_services.inventory</groupId>
            <artifactId>converter</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

我希望这两个依赖项都包含在由此模块创建的jar中。我尝试了maven shade插件,如

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <finalName>business-${artifactId}-${version}</finalName>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>

但是这捆绑每个依赖(甚至是框架)。有没有办法选择我想在最终jar中包含哪些依赖项?

1 个答案:

答案 0 :(得分:1)

您可以为阴影瑕疵指定排除:

http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <artifactSet>
            <excludes>
              <exclude>classworlds:classworlds</exclude>
              <exclude>junit:junit</exclude>
              <exclude>jmock:*</exclude>
              <exclude>*:xml-apis</exclude>
              <exclude>org.apache.maven:lib:tests</exclude>
              <exclude>log4j:log4j:jar:</exclude>
            </excludes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>