首页 > 其他分享 >找出消失的已引入的类库

找出消失的已引入的类库

时间:2024-03-13 17:58:26浏览次数:24  
标签:类库 provided 找出 compile dependency test 引入 scope runtime

最近使用软件加密的时候用到了一个密码库,顺手从Maven Repository上,把对应的坐标给粘贴下来,引入后,项目也更新了。但是发现用不了对应的库里面的函数。
对应的Maven Repository的坐标信息如下。

<!-- https://mvnrepository.com/artifact/com.tencent.kona/kona-crypto -->
<dependency>
    <groupId>com.tencent.kona</groupId>
    <artifactId>kona-crypto</artifactId>
    <version>1.0.11</version>
    <scope>runtime</scope>
</dependency>
  1. 一开始的时候,以为是类库没有下载成功。去到本地路径,找了下,地区是在的也是完整的。
  2. 然后删除类库,重新下载,重新导入项目。发现还是没法引用到对应的项目。
  3. 最后用了最原始的办法,重新新建了一个项目,把对应的包直接手工放到项目路径,居然发现可以了。
  4. 因为想到这个方法可行,就想了下两个项目的差异点,一个是maven 项目,一个是普通的项目。唯一的差异点就是POM文件。
  5. 然后打开POM文件,发现就只有这个类库的scope 是 runtime导致,项目没法引入对应的类和方法。
  6. 去掉scope后使用默认的范围,问题修复。

重新看了下官网对scope范围的定义:

Dependency Scope

Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath.

There are 6 scopes:

  • 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. A dependency with this scope is added to the classpath used for compilation and test, but not the runtime classpath. It is not transitive.

  • runtime
    This scope indicates that the dependency is not required for compilation, but is for execution. Maven includes a dependency with this scope 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. This scope is not transitive. Typically this scope is used for test libraries such as JUnit and Mockito. It is also used for non-test libraries such as Apache Commons IO if those libraries are used in unit tests (src/test/java) but not in the model code (src/main/java).

  • 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
    This scope is only supported on a dependency of type pom in the section. It indicates the dependency is to be replaced with the effective list of dependencies in the specified POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

Each of the scopes (except for import) affects transitive dependencies in different ways, as is demonstrated in the table below. If a dependency is set to the scope in the left column, a transitive dependency of that dependency with the scope across the top row results in a dependency in the main project with the scope listed at the intersection. If no scope is listed, it means the dependency is omitted.

compile provided runtime test
compile compile(*) - runtime -
provided provided - provided -
runtime runtime - runtime -
test test - test -

标签:类库,provided,找出,compile,dependency,test,引入,scope,runtime
From: https://www.cnblogs.com/kivision/p/18071183

相关文章

  • Spring核心思想之 AOP:如何影响DI并引入三级缓存解决DI中涉及代理的问题
    Spring中AOP的实现与在Spring核心思想之AOP:在自定义容器基础上实现AOP功能中实现的自定义AOP一样,采用后置处理器方式。在Spring的核心思想之DI:详解SpringDI循环依赖实现机制文中末尾提到了一个问题,为什么是三级缓存而不是二级。下面示例AOP是如何影响DI的?......
  • [C++]c++ 在项目cpp文件中直接用#pragma comment语句引入,无需配置属性表
    使用语句添加引入库的好处就是无需配置多个属性表,不管是debug模式还是release模式,不管是64位还是32位,几行代码通吃。相对路径:#ifdef_M_X64#pragmacomment(lib,"../../../VC++/DVPCamera64.lib")#else#pragmacomment(lib,"../../../VC++/DVPCamera32.lib")#endif绝......
  • JAVA实现算法问题25匹马,找出最快的3匹,但是只有5个赛道,每次比赛只能得到5匹马的速度排
    JAVA实现算法问题25匹马,找出最快的3匹,但是只有5个赛道,每次比赛只能得到5匹马的速度排序,那么最少需要多少次比赛随机数模拟25匹马匹速度importjava.lang.reflect.Array;importjava.util.Arrays;publicclassMa{publicstaticvoidmain(String[]args){......
  • Cannot read properties of null (reading '$el')找出真凶
    Cannotreadpropertiesofnull(reading'$el')菜鸟,在vue3开发遇到的问题,百思不得其解,为什么会为null,先上代码大概的代码结构:<template><el-Dialogv-model="isLoading"><el-tableref="tableRef"><el-table-colum......
  • 01js引入方式
    1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<metaname="viewport"content="width=device-width,initial-scale=1.0">6<title>Document......
  • 7-9 找出不是两个数组共有的元素
    7-9找出不是两个数组共有的元素分数10作者张彤彧单位浙江大学给定两个整型数组,本题要求找出不是两者共有的元素。输入格式:输入分别在两行中给出两个整型数组,每行先给出正整数N(≤20),随后是N个整数,其间以空格分隔。输出格式:在一行中按照数字给出的顺序输出不是两数组共......
  • dataset 判断整列是否有重复,找出重复数据
    DataTabledt=ds.Tables[0];DataViewdv=newDataView(dt);if(dv.Count!=dv.ToTable(true,jsonColumnNameNo).Rows.Count){......
  • 01引入方式
    1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<metaname="viewport"content="width=device-width,initial-scale=1.0">6<title>Document......
  • vue项目引入自定义svg
    图标可以使用element-ui的图标库、第三方的图标库或者引入svg使用,这里是讲如何使用自定义的svg。将SVG图标放入项目 自定义的svg可以访问 https://www.iconfont.cn地址,搜索你想要的图标,下载SVG格式,放入项目的src/assets/icons/svg文件夹中。并在src/assets/icons/index.js......
  • 【转】[Java]引入Redisson可能会出现项目启动失败问题解决
    转自:https://blog.csdn.net/bengbuguang4321/article/details/121951650在启动项目时,Redisson自己会启动一个Redisson连接池,尝试连接redis,这时候如果遇到网络不通就会出现问题,因为redis连接不上,导致项目启动不了解决方法是:1、重新空实现了一个RedissonClient/***@ClassNa......