scope引起的问题

简介: 背景 执行mvn clean test命令提示部分包不存在,但通过eclipse的clean操作后可以执行mvn test命令     解决方法 mvn clean操作为清空编译的class文件,test的话,会去编译test相关的文件,并执行test 根据日志提示发现,提示不存在的包,都是在pom.

背景

执行mvn clean test命令提示部分包不存在,但通过eclipse的clean操作后可以执行mvn test命令

 

 

解决方法

mvn clean操作为清空编译的class文件,test的话,会去编译test相关的文件,并执行test

根据日志提示发现,提示不存在的包,都是在pom.xml中加了<scope>test</scope>的

官方解释:

The <scope> element can take 6 value: compile, provided, runtime, test, system and import.

This scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.

compile

This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

provided

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

runtime

This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

test

This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

system

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

import (only available in Maven 2.0.9 or later)

This scope is only used on a dependency of type pom in the section. It indicates that the specified POM should be replaced with the dependencies in that POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

 

加入了<scope>test</scope>的话,包只在编译test部分和执行,而该包在非测试部分也需要引入,所以报错,提示包不存在,所以去掉<scope>即可

 
虽千万人,吾往矣!
目录
打赏
0
0
0
0
3
分享
相关文章
scope=“scope“和作用域插槽
scope=“scope“和作用域插槽
64 0
|
9月前
|
maven中scope和optional区别
maven中scope和optional区别
126 1
Dependency ‘org.springframeworkspring-context5.0.2.RELEASE‘ not found
Dependency ‘org.springframeworkspring-context5.0.2.RELEASE‘ not found
209 0
【Spring注解必知必会】全面了解@Scope
【Spring注解必知必会】全面了解@Scope
439 0
【Spring注解必知必会】全面了解@Scope
使用<scope>import</scope>解决Maven项目单继承问题
使用<scope>import</scope>解决Maven项目单继承问题
584 0
好用的伪类(:empty和:scope)
JS查漏补缺系列是我在学习JS高级语法时做的笔记,通过实践费曼学习法进一步加深自己对其的理解,也希望别人能通过我的笔记能学习到相关的知识点。这一次我们来了解两个好用的伪类(:empty和:scope)
190 0
Spring注解之@Scope
项目注册需要不能重复提交时,用到了注解@Scope
2998 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等