jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.68k stars 199 forks source link

jooby-apt should not depend on commons-text which depends on commons-lang3 #3462

Closed agentgt closed 2 weeks ago

agentgt commented 2 weeks ago

@jknack

I assume the commons-text was added to fix some escaping issues with jooby-apt.

I highly recommend you just pull out what you need because it currently is a breaking show stopper for us. Actually any annotation processor really should not have any dependencies as veritable shit show of classpath problems happen including the commons-text/commons-lang3 issue.

Here is why.

We have commons-lang3 as a runtime dependency because we ban that jar downstream however other libraries use it (in irony the only other library that uses it at the moment for us is handlebars).

So here is what happens the annotation processor runs but it does not have access to <scope>runtime</scope> jars. So you get a classpath exception like:

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project snaphop-v2-document-web: Fatal error compiling: java.lang.NoClassDefFoundError: org/apache/commons/lang3/Range: org.apache.commons.lang3.Range -> [Help 1]

Lucky for us I have already pulled out the escaping from commons-text you need in my own project JStachio: https://github.com/jstachio/jstachio/tree/main/compiler/apt/src/main/java/io/jstach/apt/internal/escape

Just copy that entire escape package and put into jooby-apt and call EscapeUtil.escapeJava.

I can put in a PR today if you like.

jknack commented 2 weeks ago

I tried to not add the dependency, but then escape got too complicated. So, yea please send a PR. Thank you.

agentgt commented 2 weeks ago

@jknack PR added. Feel free to edit it. I did not bother adding any tests as I assume there is probably already one for this.