1

I am using the rest-assured library to automate API's.

I was struggling from yesterday.

I was getting error with clean install like below:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project rest-assuredProject: Compilation failure: Compilation failure: [ERROR] /D:/Workspace/rest-assuredMaven/src/basics/twitterAPI.java:[12,22] package io.restassured does not exist [ERROR] /D:/Workspace/rest-assuredMaven/src/basics/twitterAPI.java:[14,31] package io.restassured.response does not exist [ERROR] /D:/Workspace/rest-assuredMaven/src/basics/twitterAPI.java:[16,29] cannot find symbol [ERROR] symbol: class RestAssured

Today I refer a below stack thread

Maven Compilation error [package org.testng.annotations does not exist]

one of the answers said to use compile test instead of clean install. And guess what it started working. even just test is working fine. Now I have query that why it is happening

I have observed that their are some static import present in the script. Example:

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

Is it due to same?

Also, Let me know if I need to improvise it further more

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125

1 Answers1

4

The RestAssured class is provided by the rest-assured artifact. You don't have the artifact in your dependencies and none of your compile scope dependencies depends on it, that's why install doesn't know about it.

Tests work because one of your test scope dependencies (spring-mock-mvc) depends on the rest-assured artifact. So the solution as I see it would be to add the rest-assured artifact to your compile scope dependencies:

<dependencies>
    ... current content ...

    <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>3.0.6</version>
    </dependency>
</dependencies>