Maven排除软件包

时间:2019-08-12 00:04:23

标签: maven pom.xml

我的项目是Nukkit插件,需要使用Apache Commons Lang3依赖项-因此我将其包含在pom.xml中。问题是我的Jar大小远远超过1 MB,因此我需要切出一些包装以减小大小。我尝试使用Maven Shade Plugin排除1个类(用于测试),但是当我查看.jar​​时,发现什么都没有删除,并且大小没有改变。

这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>me.yakovliam.nkdev</groupId>
    <artifactId>YakoChat</artifactId>
    <version>1.1-SNAPSHOT</version>
    <name>YakoChat</name>
    <description>Yako's Chat Plugin</description>
    <url>https://www.yakovliam.com/</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <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>
                                <excludes>
                                    <exclude>org.apache.commons.lang3.StringUtils</exclude>
                                </excludes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <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>
                    <archive>
                        <manifest>
                            <mainClass>me.yakovliam.nkdev.YakoChat.YakoChat</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                   <excludes>
                       <exclude>*:class</exclude>
                   </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>nukkitx-repo</id>
            <url>http://repo.nukkitx.com/main/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>cn.nukkit</groupId>
            <artifactId>nukkit</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.typesafe/config -->
        <dependency>
            <groupId>com.typesafe</groupId>
            <artifactId>config</artifactId>
            <version>1.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.24</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/me.lucko.luckperms/luckperms-api -->
        <dependency>
            <groupId>me.lucko.luckperms</groupId>
            <artifactId>luckperms-api</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>com.creeperface.nukkit.placeholderapi</groupId>
            <artifactId>PlaceholderAPI</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>
    </dependencies>
</project>

如您在plugins中所见,我试图排除lang3的{​​{1}}。罐子的大小没有变化。有什么办法可以做到这一点(并能够排除软件包)?谢谢!

0 个答案:

没有答案