-1

I am trying to understand a package of java code (let's call it mainPackage), which has an import from another package(Let's call this commonUtility). I can see the import statement, but cannot see the dependency directly in the pom file. I just need to understand this to make a few changes in the commonUtility so that it can be reflected in my mainPackage jar.

for example I can see a import statement in the mainPackage class file

import com.training.tdw.commonUtility.transform;

So I am expecting to see

<dependency>
  <groupId>com.training.tdw</groupId>
  <artifactId>commonUtility</artifactId>
  <version>1.0.1</version>
</dependency>

But it is not present. So how will i find out the ink between the two packages. Correct me if my understanding is wrong.

Srinivas
  • 2,010
  • 7
  • 26
  • 51
  • It's not clear what you're asking. Maven handles transitive dependencies, e.g., if PackageA in the pom file depends on PackageB then PackageB is available to your code. That said, not explicitly defining a PackageB version can be interesting because it can change from underneath you if you rev PackageA. – Dave Newton Aug 15 '17 at 16:57
  • @DaveNewton - I ahve given an example. ANy help would be appreciated. – Srinivas Aug 15 '17 at 17:04
  • I told you how: Maven handles transitive dependencies. Implicit dependencies are available to your project as well as the explicit. As the answer says you can expose the entire dependency tree. But relying on implicit dependencies can have consequences under some circumstances. – Dave Newton Aug 15 '17 at 18:00
  • Possible duplicate of [In Maven 2, how do I know from which dependency comes a transitive dependency?](https://stackoverflow.com/questions/34144/in-maven-2-how-do-i-know-from-which-dependency-comes-a-transitive-dependency) – Tom Aug 15 '17 at 21:38

3 Answers3

1

It seems at least one of dependencies defined in your pom.xml depends on com.training.tdw.commonUtility:1.0.1

So, you do not need to specify com.training.tdw.commonUtility:1.0.1 dependency explicitly in your pom.xml. That is an essence of "Transitive dependencies" feature appeared since Maven 2.

Transitive dependencies are a new feature in Maven 2.0. This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.

See: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

  • Please note that "test" scope is not transitive!
Yurii Bratchuk
  • 920
  • 9
  • 12
  • Thank you, I changed the version of commonUtility and included the dependency details (version id, group id and artifact id). I did mvn clean install in all three of them and the changes are reflected in mainPackage. – Srinivas Aug 17 '17 at 05:57
0

You can use the dependency:tree goal to find it. Try running

mvn dependency:tree -Dverbose -Dincludes=com.training.*

This assumes that the group id contains com.training, its possible however that its named something silly, you might just run a full dependency tree by removing the -Dincludes and manually looking.

Alternatively if your using an IDE you could navigate to a class inside that package and there should be an option to show it in your project/package explorer. From there you could determine the JAR file name and that should correspond to the maven package artifact id

ug_
  • 11,267
  • 2
  • 35
  • 52
  • It definitely helped. I can see the dependency tree in the jar file. I will read more about transitive dependency. Thanks – Srinivas Aug 17 '17 at 05:58
0

A jar can have an arbitrary GAV (groupId, artifactId, version), and it need not be connected to the package you import. Sure, many people start their package name by the groupId, but others don't so in general there is not direct way to infere the necessary (or used) jar from a given package.

If you are using Nexus 2 (or MavenCentral), there is a feature named "Classname search" which allows you to search for a (qualified) class name and get as a result the jars that contain such a class. Unfortunately, Nexus 3 has dropped this.

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