You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行mvn install命令时如何跳过指定jar包依赖

解决方案

你可以根据自己的项目场景选择以下任意一种方案,均无需团队成员手动下载依赖,构建出来的jar包体积可达到251MB的预期效果:

方案1:使用provided scope(最简便,无需额外配置)

将目标依赖的scope设置为provided,该依赖会正常参与编译、单元测试阶段,Maven会自动从镜像库拉取依赖供开发使用,仅在构建最终jar包时不会被打入产物:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-conversion</artifactId>
    <version>21.1</version>
    <scope>provided</scope>
</dependency>

配置完成后直接执行mvn install即可得到不含该依赖的jar包。

方案2:使用Maven Profile动态切换是否包含依赖

如果部分场景需要打包包含该依赖、部分场景不需要,可以通过profile实现灵活切换:

  1. 在pom.xml中添加profile配置:
<profiles>
    <!-- 开发测试默认激活,包含依赖 -->
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.groupdocs</groupId>
                <artifactId>groupdocs-conversion</artifactId>
                <version>21.1</version>
            </dependency>
        </dependencies>
    </profile>
    <!-- 生产构建用,不包含依赖 -->
    <profile>
        <id>prod</id>
    </profile>
</profiles>
  1. 构建小体积jar时执行命令:
    mvn install -Pprod

方案3:Spring Boot项目专属,直接在打包插件中排除

如果你使用的是Spring Boot框架,可以直接修改spring-boot-maven-plugin配置,无需修改依赖声明:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>
                        <groupId>com.groupdocs</groupId>
                        <artifactId>groupdocs-conversion</artifactId>
                    </exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

配置完成后直接执行mvn install即可。

内容的提问来源于stack exchange,提问作者Robert Gardziński

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 00:09:04