asx
asx

Reputation: 41

How to access the dependency version in code?

How can I get the dependency version which I have added in pom from the Java/Scala Code? I don't want to fetch the version of the project, I want to fetch the version of the External Libraries which pom fetches it.

Upvotes: 0

Views: 1223

Answers (1)

Gal Naor
Gal Naor

Reputation: 2397

Just type mvn dependency:tree If you want to check a specific external library, do this: mvn dependency:tree -Dverbose -Dincludes=[groupId]:[artifactId]:[type]:[version]

If you want to do it on runtime (for example for apache http client):

Class<?> clazz = org.apache.http.client.HttpClient.class;
Package p = clazz.getPackage();
System.out.printf("%s%n  Title: %s%n  Version: %s%n",
                      clazz.getName(),
                      p.getImplementationVersion());

Upvotes: 2

Related Questions