3

In Maven, I have quite a few dependencies that IntelliJ import. I also have the one for CSVReader

<dependency>
    <groupId>com.opencsv</groupId>
    <artifactId>opencsv</artifactId>
    <version>5.2</version>
</dependency>

In the class that uses it, I have import com.opencsv.CSVParser;. It says, "Cannot resolve symbol CSVParser". It gives me an option to add library to classpath. I'm hesitant to do this as last time I did this, it resolved the error but wouldn't allow me to run my Spring Boot application. Why can't the library just be imported like the other ones?

BobbKitty729
  • 327
  • 1
  • 6
  • 13
  • Your dependency is correct looking at https://search.maven.org/artifact/com.opencsv/opencsv/5.2/jar have you got a conflict perhaps with the Apache commons lib? http://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVParser.html – Rob Evans Jun 10 '20 at 21:41
  • @RobEvans Maybe, I have ```org.apache.commons``` also as a dependency in my pom.xml – BobbKitty729 Jun 10 '20 at 21:44
  • Seems you will have a conflict then. https://stackoverflow.com/questions/547805/exclude-all-transitive-dependencies-of-a-single-dependency might help you but you'll need to decide whether the additional opencsv lib is needed or whether the (transitive?) apache dependency is wanted – Rob Evans Jun 10 '20 at 21:47

2 Answers2

4

Had the same issue. A right-click on the project -> Maven -> 'Reload project' may probably fix it.

  • 1
    That sounds very much like a best guess. It would be an "okay" comment, but it is no way an answer to the question and the potential conflict of dependencies as outlined in the comments 1 year back. – GhostCat Oct 12 '21 at 09:30
  • 3
    @GhostCat This is actually a relevant answer. Reloading project to sync newly added maven dependencies solves it. From the title Aliye wanted the error solved. – Elated Coder Feb 18 '22 at 05:07
-1

Commenting out lines where you used the dependency and then building the project once and reloading helps.

Innomight
  • 556
  • 3
  • 15