网站商城系统,googleplay官网,大连网络工程,网站建设的主要观点1.compile#xff08;默认#xff09;
含义#xff1a;表示该依赖在项目的所有阶段#xff08;编译、测试、运行#xff09;都需要。
当你依赖一个库#xff0c;并且这个库是你项目的核心部分#xff0c;比如 Spring Boot 的spring - boot - starter - web#xff0c…1.compile默认
含义表示该依赖在项目的所有阶段编译、测试、运行都需要。
当你依赖一个库并且这个库是你项目的核心部分比如 Spring Boot 的spring - boot - starter - web它的scope就是compile。这意味着在编译项目代码时需要它在运行单元测试时也需要它并且最终在打包后的应用程序运行时同样需要它
示例
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring - boot - starter - data - jpa/artifactIdscopecompile/scope
/dependency
2. test
含义这种依赖只在测试阶段例如执行单元测试或集成测试需要。
当你有一些专门用于测试的库如junit - vintage - engine用于在 JUnit 5 中运行 JUnit 4 风格的测试你可以将其scope设置为test。这样在编译主代码或者打包运行应用程序时这些测试库不会被包含进去从而减小了最终打包产物的体积。
示例
dependencygroupIdorg.junit.vintage/groupIdartifactIdjunit - vintage - engine/artifactIdscopetest/scope
/dependency
3.provided
含义表示这个依赖在编译和测试阶段需要但在运行时期望由运行环境如应用服务器来提供。
一个典型的例子是 使用外置tomcat。当你开发一个 Web 应用时你需要 应用服务器如 Tomcat时服务器本身已经提供了tomcat所以你不希望将其打包到你的应用程序中。
示例
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-tomcat/artifactIdscopeprovided/scope
/dependency
4.runtime
含义这个依赖在编译阶段不是必需的但在运行和测试阶段是需要的。比如数据库驱动在编译代码时你不需要它但是在运行应用程序连接数据库以及进行测试时就需要它。
示例
dependencygroupIdcom.mysql/groupIdartifactIdmysql - connector - java/artifactIdscoperuntime/scope
/dependency
在这里mysql - connector - java用于在运行时连接 MySQL 数据库编译阶段不需要该驱动类所以scope设置为runtime。