即使添加到Maven Project后也无法找到/导入“ io.rest-assured”软件包

问题描述

我将以下依赖项添加到了maven项目pom.xml文件中,并进行了mvn清洁,安装。我可以在我的C驱动器/用户中看到添加到.m2文件夹的依赖项,但是它们未在IntelliJ“外部库”部分下列出。另外,当我尝试将它们导入到班级时,我没有看到它们,并且出现“未找到”错误

添加依赖项-

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-path</artifactId>
        <version>3.3.0</version>
    </dependency>
  
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>4.3.0</version>
    </dependency>

enter image description here

解决方法

我认为可能是因为缺少<scope>。默认范围是compile,如果未指定,则使用默认范围,但是我们在这里需要test

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-path</artifactId>
    <version>4.3.1</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>4.3.1</version>
    <scope>test</scope>
</dependency>