The import io.restassured.RestAssured cannot be resolved
Asked Answered
C

3

11

Hi I am not able to resolve the error while using rest assured 4.1.1. library in my Eclipse IDE. I have added the rest assured library in my pom.xml file still the error is not resolved.

I tried re-importing the rest assured library from https://mvnrepository.com/artifact/io.rest-assured/rest-assured/4.1.1 But still doesn't work

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RestAssuredTutorial</groupId>
<artifactId>RestAssuredTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
  <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>4.1.1</version>
      <scope>test</scope>
  </dependency>
 <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json- 
 simple -->
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1.1</version>
  </dependency>
  <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.6</version>
 </dependency>

 </dependencies>
</project>

The import io cannot be resolved

Corrida answered 23/10, 2019 at 4:53 Comment(0)
A
25

You have the scope set to test when you are adding the mentioned dependency. This limits your code from accessing that dependency's classes within your source code. That is, you can access those classes only within your test sources (ex: ${project.dir}/src/test/java/<package>, ${project.dir}/test/<package>.

If that is not your intended use case, just remove the scope attribute.

  <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>4.1.1</version>
  </dependency>
Abet answered 23/10, 2019 at 5:1 Comment(3)
Thanks a lot Imesha for the valuable and lucid explanation.Corrida
Ya after changing the scope from test to compile. I can access the package from outside the src/test/java/ packages.Glasgow
If we use gradle, what is the solution ?Lifeguard
P
0

You can go to project>build automatically in case rest assured or any other methods are not importing .

This works for me!!

Proulx answered 2/11, 2022 at 22:3 Comment(0)
Y
0

In this case we have to go at pom. Xml below this we can see dependencies bar click on this. Then click on rest assured jar then click on add. Mention artifact and group id and click

Yvette answered 3/11, 2022 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.