Cannot resolve symbol MockedStatic - java

I'm trying to import MockedStatic into a test but am not having any luck. My pom.xml file contains:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.10.0</version>
<scope>test</scope>
</dependency>
I use the following line to build the project:
mvn clean -U install appengine:run -Dapp.devserver.port=8888 -DskipTests=true
I am using IntelliJ and I get a "cannot find symbol" error for the import:
import org.mockito.MockedStatic;
Any idea what I'm doing wrong?

Turns out reloading project was all that was needed, as tgdavies suggested.
With Maven Helper plugin: right click on project folder > Run Maven > Reimport

Related

Order for building dependencies by mvn

Greeting, guys.
Could you please help me solve the issue:
In my pom.xml (for example application calls 'maven-Hell') i have 2 dependencies:
<dependency>
<groupId>com.dor.lub</groupId>
<artifactId>aaa</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.dor.dabu</groupId>
<artifactId>ddd</artifactId>
<version>3.3.3</version>
</dependency>
When i run mvn clean install for 'maven-Hell' application I want to build (clean install, as well) for two dependencies (see above) before 'maven-Hell' app.
P.S. They are also my modules, not like parent and child.
Any idea how to do it?
Thanks!
mvn clean install -pl MICRO-SERVICE-NAME -P mvnProfile -am -f pom.xml
Mvn will run clean install on owns modules from project

Can't import dependencies that have been downloaded to .m2

I'm importing dependencies via Maven:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1203-jdbc4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
I checked C://Users/user/.m2/repository and I can see those dependencies in .jar files in respective folders/packages. However when I try to import those in code:
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
I get Cannot resolve symbol error:
I tried;
mvn clean
mvn install
mvn clean install
I get compile error on mvn install. I tried removing all source code fromt he project and then mvn install, it resulted in Build Success, however once the source code is added, I can't use the dependency classes.
This answer helped me. Turned out the dependencies Maven downloaded were assigned a Run time scope (whose idea was to invent this useless error-prone scope??). I set the scope to compile (File - Project structure - Modules - Dependencies - Scope) and it works fine.
Something is wrong you should check your project from first:
maven Repositories in your IDE Updated True?
run "mvn Clean" in IDE Console
Reimport All maven Project
go to pom.xml and check your dependencies.
Good luck.

Adding a new dependency to pom does not work in eclipse

I am having an issue while adding a new dependency to my pom.xml. I have an existing Maven project in eclipse. I added a new dependency to my pom.xml as follows:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
After that I right clicked on the project --> Maven -->Update project. However, there is a compilation error for the class for the following line:
private JavaMailSender mailSender;
The JavaMailSender is not found. Any idea what might be the issue?
You could try to do right click on the project > Maven > Update project and check "Force update of Snapshots/Releases"
Or you can force to download the dependencies from terminal with the following command:
mvn clean install -U
You need to add the dependency, then compile it.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>

Unable To Use ch.qos.logback.classic Classes

I have spring project setup on Intellij Idea 2016.2 using Maven. For some reason I cannot import or use any class present in ch.qos.logback.classic package. I tried to invalidate cache, re-import maven dependencies.
For example with
import ch.qos.logback.classic.Level;
the IDE says 'cannot resolve symbol Level'. When compiling from command line it says 'package ch.qos.logback.classic does not exist'. Any suggestion what might be wrong?
Update - found the issue. I had set dependency scope to compile. Updating this fixed the issue.
Have you added the ch.qos.logback:logback-classic Maven artifact in your dependencies?
You should have something like that in your pom :
<dependencies>
...
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
...
<dependencies>

TestNG-functionality not recognized by Intellij

I am trying to use TestNG to test my Java-code. The TestNG-plugin is installed in IntelliJ, and the dependency:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
has been added to Maven. However, when I write "#Test" in a class, IntelliJ gives the error-message: "can not resolve symbol 'Test'.
Importing org.testng.annotations.Test is not recognized either. It just seems like Intellij is ignoring the Maven-dependency.
Here is the project structure and the error:
Should I have done something more with TestNG, rather then just adding the Maven dependency?
Run mvn clean
Set the scope of testng to test, i.e.:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.12</version>
<scope>test</scope>
</dependency>
Run mvn install

Categories