This post is about the Maven dependencies not resolving. I'm recording the incident, my understanding, and what worked for me. It can help a fellow Software Test Engineer.
Incident and its Details
I'm using the machine which has the below setup:
- OS: Windows 10 Pro
- IDE: IntelliJ IDEA 2022.13 (Community Edition)
- JDK: 1.8
- Maven: 3.5.4
I created a new Maven project and in the pom.xml, I added the below dependencies. The IDE showed that these dependencies are not resolved.
<dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>4.3.0</version></dependency><!-- https://mvnrepository.com/artifact/org.testng/testng --><dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>7.3.0</version><scope>test</scope></dependency><!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager --><dependency><groupId>io.github.bonigarcia</groupId><artifactId>webdrivermanager</artifactId><version>4.3.1</version></dependency><!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured --><dependency><groupId>io.rest-assured</groupId><artifactId>rest-assured</artifactId><version>4.4.0</version><scope>test</scope></dependency>
I observed, that the added dependencies not getting resolved, that is, not getting added to libraries. In the IDE, I see the error as this:
- Dependency 'io.github.bonigarcia:webdrivermanager:4.3.1' not found
- Dependency 'org.seleniumhq.selenium:selenium-java:4.3.0' not found
- Dependency 'org.testng:testng:7.3.0' not found
- Dependency 'io.rest-assured:rest-assured:4.4.0' not found
Note: I have other Maven projects to which I have added the same dependencies but of different versions, in my workspace. Each time I add a dependency it will download to the libraries in my workspace though it exists, and this is my configuration in IDE.
At this point, I did not know what is happening and how to approach resolving this problem. All I know is, that there are other versions of the same dependencies in the Maven's library on my machine.
Understanding the Problem
I tried to understand what it is saying to me. It says it cannot find the dependency. Could be that it is looking for the dependency in the Maven's library on my box, and it is not finding it.
Further, I looked into the web to see did someone else face the same incident and said behavior. Few posts said using the "compile" scope solved the problem in their case for WebDriverManager. But, how can the change in scope fix the dependency not found incident? This was the question in me! To my curiosity, I did try that for WebDriverManager; I did not see any change.
Invalidating the Cache - Is that a Fix?
In the IntelliJ IDE, I tried to invalidate the cache and reboot the IDE and open the project. I see the dependencies being resolved and I do not see the said problem.
I don't know how this fixed the said problem here. Also, I don't know precisely what exactly the problem is, here. Invalidating the cache and reopening the IDE (also the project) worked.
On invalidating cache, here is what happens per IntelliJ:
- Removes the cache files for all projects ever run in the current version of IDE
- The files will be recreated the next time you open these projects
I remember now that I upgraded the IntelliJ to the latest version before creating the said new Maven project, here. Later, it resulted in the above said dependency problem.
Note that, I had created a few Maven projects using an older version of IntelliJ. I have the same dependencies in the old and new projects, just the version of these dependencies is the only difference.
Now, invalidating the cache on this new version of IntelliJ, it got fixed. I understand that the IDE uses the cached instances of these dependencies. Could be there is a relationship between this cache, dependency versions, and the IDE version? I'm technically not sure of the same, but my instincts say it is.
No comments:
Post a Comment
Please, do write your comment on the read information. Thank you.