rest-assured: The import io.restassured.RestAssured cannot be resolved
Hi Johan,
I am getting the red squiggly lines when I use the below static imports:
import static io.restassured.RestAssured.*; import static io.restassured.matcher.RestAssuredMatchers.*;
My POM. xml has the below dependencies:
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>3.0.3</version>
</dependency>
<!-- to validate that a JSON response conforms to a Json Schema -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/xml-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>3.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-library -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.beust/jcommander -->
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.18</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
And my imports for the time being are: import static io.restassured.RestAssured.; import static io.restassured.matcher.RestAssuredMatchers.; import static org.hamcrest.Matchers.; import java.io.IOException; import java.io.InputStream; import java.util.List; import static io.restassured.path.json.JsonPath.; import org.testng.annotations.Test; import io.restassured.path.json.JsonPath;
Don’t know where am I missing something. Also the given() etc (without any parameter) is not showing in the IntelliSense. Please help!!

About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 13
- Comments: 53
The reason is the
<scope>test</scope>The fix for version 4.1.1 is to add some transitive dependencies:
They are now excluded in the
maven-bundle-pluginrest-assured 4.1.1 configuration. See the negated packages in the<Export-Package>of https://repo.maven.apache.org/maven2/io/rest-assured/rest-assured/4.1.1/rest-assured-4.1.1.pomI’m having this same problem.
@ramanojha Maven 4.0.0, Eclipse Neon, RestAssured 3.0.0 (scope test).
I don’t think
RestAssured.given()is necessary. If you import it like I do, such asimport static io.restassured.RestAssured.given;, then you can use justgiven()and know exactly where it comes from.remove <scope>test</scope> from your pom dependency and it will work. as Suggested above by r-simlinger. It is working for me.
Removing the scope as test could solve it, but its not the right thing to do. Follow the solution suggested by @oharsta
In rest assured versions above 4.x, explicit packages are excluded.
And so, you need to explicitly provide certain entries which are excluded.
Solved this error by using earlier versions of Rest Assured and TestNG. Also added dependency for groovy-all. So my current POM is:
Please tell what are the other dependencies should be there when using rest-assured 3.0.3 or can you tell how to know all the compile time dependencies which are going to be needed for using version 3.0.3 of Rest Assured. Thanks!
nice it works after remove scope
Removing <scope>test</scope> worked for me
I had this problem for a couple of years, last time I just bailed on 3.x. This time I pushed thru as indicated above this is maven jar file problem, goto the command line and try this:
mvn clean test-compilesee if you get something like this:
invalid LOC header (bad signature)I had this issue for both rest-assured and groovy, I assume they are related. I moved the entire rest-assured and groovy dirs to a new name to force a re-download and it works!!!
No need to change scope.
I saved the original non-working m2 sub dirs, @johanhaleby let me know if you need any input
Do not remove the test scope. You do not want test classes in your production JARs.
I am using Kotlin with Java > 9 so my test dependencies look as follows
I got back my
RestAssured.*classesRemoved test from scope it worked for me in 4.3.0 @all
Try running maven->update if your are using eclipse. Select project - right click - maven - update
Try to ignore the version :
I would like to suggest please continue with RestAssured.given() instead of just given() RestAssured. given(). get(url). getStatusCode();
suthakar79 make sure you have this line import static io.restassured.RestAssured.*; in ur step definition file