15

I am wondering what is the difference between Apache Commons Lang3 (org.apache.commons.lang3) vs Apache Commons Text (org.apache.commons.text)?

I saw many similarities between them.
For intance, they both have StringEscapeUtils:

But I also saw many differences.
So which one should I use, Lang3 or Text?
Or what are the common use cases for each of these two?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
fluency03
  • 2,637
  • 7
  • 32
  • 62
  • 2
    Read the docs that you yourself linked to. The commons-lang3 version has been deprecated in favor of the commons-text version. I imagine that the other similarities you find will have similar deprecation reasons/messages. – rmlan Oct 23 '17 at 15:42
  • Simple suggestion. Avoid using any deprecated API. – Naman Oct 23 '17 at 15:44
  • https://commons.apache.org/proper/commons-lang/article3_0.html – OneCricketeer Oct 23 '17 at 15:54

2 Answers2

5

Well, the text method states

This code has been adapted from Apache Commons Lang 3.5.

Looks like they simply plan on moving the method from one library to the other. You'd have to get the authors of that code to explain why.

However, worth pointing out that lang3 is a compile dependency of text, therefore if you included text, you would have lang3 anyway

https://github.com/apache/commons-text/blob/master/pom.xml#L61-L65

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 4
    *".... therefore if you included text, you would have lang3 anyway"*. Unless they decide to change the implementation!. It is not a good idea to rely on undocumented dependencies. – Stephen C Oct 23 '17 at 16:04
  • @StephenC Where is it not documented? https://github.com/apache/commons-text/blob/master/pom.xml#L61-L65 – OneCricketeer Oct 23 '17 at 18:21
  • The projects serve a different purpose - One is a dependency of the other. I don't contribute to Apache Commons, so I can't answer why they are copying code between projects – OneCricketeer Oct 23 '17 at 18:23
  • 6
    Since you asked. It is not documented in the javadocs. Do you think that they would hesitate to remove the "lang3" dependency from the POM file if they refactored `text`? They are unlikely to consider the "edge case" of someone needing to use both APIs. If an app programmer *does* want / need to use both `lang3` and `text` in his code, it is **prudent** to have explicit dependencies for both. – Stephen C Oct 23 '17 at 22:35
  • 3
    Reference: http://www.kyleblaney.com/maven-best-practices/ - "Used undeclared dependencies" – Stephen C Oct 23 '17 at 22:42
1

Text utils in commons-lang3 are marked with deprecation and the Javadoc points to commons-text

TapakSakti
  • 11
  • 1
  • 1
    Consider editing your answer to address the OP's questions, which are "So which one should I use, Lang3 or Text? Or what are the common use cases for each of these two?" – Bill Horvath Nov 09 '21 at 21:49