1

I have implemented the spring boot project with starter parent pom version 2.0.3. When I try to use

import org.apache.commons.lang.StringUtils

it throws error import cannot be resolved. Even though my m2 folder (C:\Users\.m2\repository\org\apache\commons) have lang package (commons-lang folder)installed. I also have commons-lang3 folder. If I change import to

import org.apache.commons.lang3.StringUtils

It works fine.

I have same version of starter pom in other spring boot project and there I am able to use commons.lang. Not able to identify the root cause.

Vishnu Dahatonde
  • 179
  • 2
  • 13

2 Answers2

4

As far as I can see the spring boot starter parent depends only on commons-lang3 and not on commons-lang (which is reasonable because commons-lang3 is a newer replacement for commons-lang).

It doesn't matter that your .m2 directory contains commons-lang (probably due to some other project depending on it): as long as your project hasn't declared a (direct or indirect) dependency on commons-lang, none of its classes will be on your classpath.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • My bad. Should have mentioned. I have same version of starter pom in other spring boot project and there I am able to use commons.lang. Have updated the question with this info. – Vishnu Dahatonde Aug 22 '19 at 11:06
  • 1
    @VDevD: do you have any other dependencies in the other project? It's possible that one of your other dependencies pulls in commons-lang as a transient dependency. Also: why do you *need* commons-lang when you already have commons-lang3? – Joachim Sauer Aug 22 '19 at 11:17
  • I checked other projects. I do have other dependencies, but none of those are giving apache.lang. – Vishnu Dahatonde Aug 26 '19 at 04:22
  • Have you checked `mvn dependency:tree` on the other project as suggested by the other answer? – Joachim Sauer Aug 26 '19 at 09:48
1

Call mvn dependency:tree on your "other" project. Here you can see through which path you drew commons-lang. Joachim Sauer is probably right and it is a transitive dependency that you started to use like a direct one.

Best fix would be to start to use commons-lang3 for your project (again, Joachim Sauer is right here), second best fix would be to declare commons-lang as a direct dependency in your pom.xml.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142