In my opinion, we can get the dependency tree by analyzing the pom.xml files recursively without the binary files of these dependencies. However, I find that maven sometimes will download some binary files when I run mvn dependency:tree. Why are these files downloaded?
Might be because maven dependency plugin has its own dependencies:
> [INFO]
> org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
> [INFO] +-
> org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
> [INFO] | \- commons-validator:commons-validator:jar:1.2.0:compile
> [INFO] | \- commons-digester:commons-digester:jar:1.6:compile
> [INFO] | \-
> (commons-collections:commons-collections:jar:2.1:compile - omitted for
> conflict with 2.0)
More detail is in maven-dependency-plugin
Related
way is the spring-core-6.0.4.jar in the final fat jar file
(and all the other files with ends with compile in the dependency tree if the parent is set to test scope)
[INFO] com.example:spring-boot:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.0.2:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:3.0.2:test
[INFO] +- org.springframework:spring-core:jar:6.0.4:compile
[INFO] | \- org.springframework:spring-jcl:jar:6.0.4:compile
[INFO] +- org.springframework:spring-test:jar:6.0.4:test
to make this just goto https://start.spring.io/
make de default project
and type mvn clean install
look into the jar file in sub folder \BOOT-INF\lib here you will see spring-core file there is coming from a parent with test scope
I am trying to find a explanations on how it is working
And find a possible way to make sub dependencies compile scope from a parent test scope not ending up in the jar file
Maven provides a way to show a list of all resolved dependencies with mvn dependency:list:
[INFO] The following files have been resolved:
[INFO] org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] org.hibernate:hibernate-core:jar:5.2.3.Final:compile
[INFO] javax.inject:javax.inject:jar:1:compile
[INFO] javax.annotation:jsr250-api:jar:1.0:compile
[INFO] org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] com.fasterxml:classmate:jar:1.3.0:compile
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:com:compile
[INFO] javax.el:el-api:jar:2.2:compile
[INFO] org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
Gradle's dependency report is in a tree structure, which makes it difficult to clearly see version is finally used.
Is there a command or something that gives me this list of the resolved dependencies without the tree structure?
If you execute the followin at the command line (in your gradle project dir)
gradle tasks
You'll see the following in the list
Help tasks
----------
dependencies - Displays all dependencies declared in root project 'xyz'.
dependencyInsight - Displays the insight into a specific dependency in root project 'xyz'
More info here
I am learning Spring and Hibernate with Maven. However I am not able to understand the incompatible package issue. There is not such information about which Spring package is compatible with which Hibernate packages. It's like I have to copy the POM file from existing working projects. But I am not convince with this approach. There must be some way to know the compatibility between the dependencies.
Also there is no way to determine which packages are to be included if I wanted to work with Spring and Hibernate.
I am sure there must be a way. Please help me.
I understand you question in that way, that you want to know wich versions to use (not which dependencies to use at all)
You could have a look at the spring boot poms. (I do not want you to use Spring Boot).
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
(https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml)
They contain a lot of knoweleg which versions work together well.
For example:
<spring.version>4.2.4.RELEASE</spring.version>
<hibernate.version>4.3.11.Final</hibernate.version>
Maven has a plugin that shows dependencies of an artifact in a tree view. You can use it to see dependencies of a pom.xml. For example, you can download pom.xml from jCenter or Maven Central, and run the following command:
mvn -f your-downloaded-pom.xml dependency:tree
And it will show something like that:
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # spring-orm ---
[INFO] org.springframework:spring-orm:jar:4.1.6.RELEASE
[INFO] +- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- javax.jdo:jdo-api:jar:3.0.1:compile
[INFO] | \- javax.transaction:jta:jar:1.1:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] +- org.apache.openjpa:openjpa:jar:2.2.2:compile
....
If you want to know the hibernate dependencies for Spring, you can obtain Spring-ORM pom.xml for the version you want, for example 4.1.6.RELEASE and run the following command:
mvn -f spring-orm-4.1.6.RELEASE.pom dependency:tree | grep hibernate
and you will get this:
[INFO] +- org.hibernate:hibernate-core:jar:4.3.8.Final:compile
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.6.10.Final:compile
So this is how you can get it.
Hope it helps!
I have 2 projects, when I list the dependencies of the first I get:
[INFO] com.onespatial.gothic:gothic-java:jar:5.16
[INFO] +- com.onespatial.tools.gde:gde-cfg:zip:5.16:provided
[INFO] +- com.onespatial.gothic:gothic-w32:jar:5.16:compile
[INFO] \- com.onespatial.gothic:gothic-lx86_64:jar:5.16:compile
which is correct. The gde-cfg is provided. However when I list the dependencies of the second project, which includes the above project, I get:
[INFO] +- com.onespatial.radius.studio:rswebmapservice:jar:classes:2.3.4-build-7-SNAPSHOT:compile
[INFO] | +- com.onespatial.gothic:gothic-java:jar:5.16:compile
[INFO] | +- com.onespatial.gothic:gothic-lx86_64:jar:5.16:compile
[INFO] | +- com.onespatial.gothic:gothic-w32:jar:5.16:compile
The transitive dependency of gothic-java is not appearing in the tree (or when I use dependency:list). Can anyone explain why gde-cfg is not being listed above.
As described in the Maven docs, transitive provided dependencies are not added to the dependency tree. There is a bug report from 2006, with no progress since.
You are meant to declare all the dependencies you are using in your project, in the sense that if you are using classes from gde-cfg, you should declare it in your dependencies, unrelated to whether there is a transitive dependency on it.
The only case that I can think of where the dependency would be necessary without you not actually using any classes from gde-cfg, is if you are extending a class/interface from gothic-java, and this class/interface extends a class/interface from gde-cfg. In this case the class/interface would have to be present at compile time, which it is not in Maven’s current behaviour. The workaround would be to manually add a provided dependency to gde-cfg to your project.
Should "mvn dependency:list -DincludeScope=compile" include child dependencies of test scope deps?
My project depends on "org.apache.httpcomponents:httpclient:jar:4.1:test"
and httpclient depends on "org.apache.httpcomponents:httpcore:jar:4.1:compile"
If I look at compile scope dependencies, I do not expect to see anything below httpclient since it is test scope and that branch of dependencies should be filtered out.
However, the following includes core" lists httpcore
mvn dependency:list -DincludeScope=compile -DexcludeScope=test|grep -i http.*core
[INFO] org.apache.httpcomponents:httpcore:jar:4.1:compile
My Project's dependency:tree output
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.1:test
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.1:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1:test
[INFO] | \- commons-codec:commons-codec:jar:1.4:compile
Am I missing a flag that handles this "properly" or am I misunderstanding what proper is in this situation.
Oh, it's a bug (http://jira.codehaus.org/browse/MNG-3089) explained in this thread http://www.mail-archive.com/dev#maven.apache.org/msg68011.html but not fixed.