zoukankan      html  css  js  c++  java
  • scope引起的问题

    背景

    执行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>即可

     
  • 相关阅读:
    python列表、字典、循环结构练习题
    python的数据类型
    git配置子模块
    zabbix通过jmx采用默认tomcat模板监控tomcat好多值不支持的问题排查
    阿里云ecs自定义监控项
    开源跳板机jumpserver的安装部署和使用详细教程及踩坑经验
    kubernetes介绍
    git使用方法
    20199323 2019-2020-2 《网络攻防实践》第4周作业
    20199323 2019-2020-2 《网络攻防实践》第3周作业
  • 原文地址:https://www.cnblogs.com/jwentest/p/7073199.html
Copyright © 2011-2022 走看看