一个项目的pom.xml如果使用了scope为system的depend后,会导致传递依赖中断

参考:https://blog.youkuaiyun.com/xjyr/article/details/79832408

概述:
maven 的<dependency>的scope属性可以为system,因为有些你依赖的jar包可能是没有maven坐标的,它完全不在maven体系中,这时候你可以把它下载到本地硬盘,然后通过system来引用

不过不推荐使用system,因为一个项目的pom.xml如果使用了scope为system的depend后,会导致传递依赖中断,即所有其他依赖本项目的项目都无法传递依赖了。

比如:假设A项目依赖了m.jar,  n.jar, x.jar,  然后我们把A项目打包成了a.jar,  如果此时B项目依赖了A项目,则B项目通常自然就已经默认传递依赖了m.jar,  n.jar, x.jar。

但是如果A项目的pom.xml文件出现了scope为system的depend,则B项目就只能依赖a.jar, 将无法传递依赖m.jar,  n.jar, x.jar

解决方案:

1、使用maven私服,这样就不需要设置scope为system了

2、由于scope设置的system会导致第三方jar的依赖传递中断,这就会导致缺少第三方jar需要的一些依赖,这个就需要人工补齐缺少的dependency,或者第三方如果有源码,可以作为module引入项目,这样也可以解决

解决打包时scope为system的jar没有打进jar的问题:

主要起作用的是:

                <configuration>
                    <!--将scope为system的依赖也打进jar包-->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!--将scope为system的依赖也打进jar包-->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
        <!--如果不加package打包中没有mapper.xml文件-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值