依赖性弹簧启动测试未在多个模块Maven项目中继承



在我的多模块maven项目中,所有模块都具有我自己的"常见"模块的依赖关系,例如,例如,模块" a"具有这种依赖性"。并且"常见"模块具有spring-boot-starter-test依赖关系。但是,当我在此"一个"模块中编写单元测试时,它表明测试依赖项未导入。然后我检查依赖项,发现spring-boot-starter-test未导入。我想问为什么?从我的意义上讲,模块" a" ref" common," common" ref spring-boot-starter-test,因此模块" a"应该参考 spring-boot-starter-test,但事实不是。顺便说一句,尽管有spring-boot-starter-test,其他依赖性通过Hirachy效果很好。有人知道为什么是吗?预先感谢您。

最有可能在模块中" deperionecy spring-boot-starter-test具有范围test。具有这种范围的依赖性不是传递的。请参阅依赖关系范围 https://maven.apache.org/guides/introduction/introduction-to-depentency-mechanism.html。最好的解决方案是依赖管理。请参阅依赖项管理

简要地,您需要创建Parrent模块并声明依赖性管理拟南芥:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>A</artifactId>
            <version>1.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

然后从父母那里继承您的模块,并在没有versionscope

的情况下声明依赖性
    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>A</artifactId>
        </dependency>
    </dependencies>

最新更新