Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on incorrect Jackson version at runtime? #22

Open
ivarref opened this issue Aug 9, 2019 · 0 comments
Open

Warn on incorrect Jackson version at runtime? #22

ivarref opened this issue Aug 9, 2019 · 0 comments

Comments

@ivarref
Copy link

ivarref commented Aug 9, 2019

Hi,

and thanks for a fine library!

Re the twitter thread https://twitter.com/arcatan/status/1159690520194670598

Do you know if there’s something that jsonista could do better around this? Mixed-up Jackson deps seems to be a thing that keeps happening.

I'm not sure this is a good suggestion, but one option is, at runtime, to verify Jackson versions. This is stored inside for example META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties.

~/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.9$ unzip -p jackson-core-2.9.9.jar META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties
#Generated by org.apache.felix.bundleplugin
#Wed May 15 19:58:39 PDT 2019
version=2.9.9
groupId=com.fasterxml.jackson.core
artifactId=jackson-core

I'm no Java/JAR-expert, but this file is similarly also stored inside my uberjar (packed by boot).

$ unzip -p target/app.jar META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties
#Generated by org.apache.felix.bundleplugin
#Mon Jun 11 17:53:30 PDT 2018
version=2.9.6
groupId=com.fasterxml.jackson.core
artifactId=jackson-core

Thus the version can be read in Clojure, at runtime, with something like this:

(defn dump-version [pom-props]
  (some->> (io/resource pom-props)
           (slurp)
           (str/split-lines)
           (filter #(str/starts-with? % "version="))
           (first)
           (seq)
           (drop (count "version="))
           (str/join "")))

$ (dump-version "META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties")
=> "2.9.9"

When an incorrect version is detected, an error/warning could be printed.

I have not myself written code like this that is running in production, but if it saves hours of devs debugging time with strange behaviour due to a slightly incorrect dependency, it might be worth it?
Consider this a suggestion.

CC @miikka @hlship

Thanks and kind regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant