使用排除源程序包和选定的依赖关系来构建Maven可执行jar

时间:2019-01-11 05:24:35

标签: maven maven-plugin maven-shade-plugin maven-jar-plugin

我正在尝试构建Maven可执行jar,其中排除了很少的源程序包,     并添加选定的依赖项。     我尝试了两个插件,这些插件可以给我带来接近的结果,但不是一个确切的插件。     1. Maven-Jar-Plugin -使用此插件,可排除源软件包,但无法选择对jar的依赖项。     2. Maven-shade-plugin -使用此插件,我可以选择依赖关系,但不能排除源软件包。

Please suggest me any plugin/idea to achieve this.

Thanks in advance.

1. *Maven-Jar-Plugin* - With this plugin, Source packages are excluded, but not able to selected dependencies to jar.
2. *Maven-shade-plugin*- With this plugin, i am able to selected depndencies, but not able to exclude source packages.

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
        <execution>
        <id>deploy</id>
        <goals><goal>jar</goal></goals>
        <phase>package</phase>
        <configuration>
         <classifier>deploy</classifier>
          <excludes>
            <exclude>**/spark/**</exclude>
            <exclude>**/sparkcommon/**</exclude>
          </excludes>
        </configuration>
        </execution>
        </executions>
        </plugin>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
            <minimizeJar>true</minimizeJar>
                <artifactSet>
                <includes>
                <include>org.apache.xmlrpc:*</include>
                <include>com.sample.rocfm:*</include>
                <include>xml-apis:*</include>
                <include>org.apache.ws.commons.util:*</include>
                </includes>
                </artifactSet>
        <shadedArtifactAttached>true</shadedArtifactAttached>
        <shadedClassifierName>sample</shadedClassifierName>
            </configuration>
          </execution>
        </executions>
      </plugin>


Expected Output is a executable jar with selected dependencies, and excluding few source package. 

0 个答案:

没有答案