i have hirarhy of modules.
I set up version of hibernate-validator as 6.1.5.Final
But when i build project version of library another
maven dependencies: tree ouput
org.hibernate:hibernate-validator:jar:5.3.4.Final:compile
I can not understand how it works.
I put all dependency tree here https://paste2.org/CwB2H4W2
Problems with dependencies should always bring you to the "Dependency Hierarchy" Tab of your POM.xml. There you will see your projects dependencies, and dependencies of that dependencies.
If I had to guess I'd say there you will find a module providing the dependency you think you don't use.
Further information to maybe change this:
First declared dependencies get used first. So if you define your dependency before the Module that brings the other dependency in, Maven should select yours.
Related
I am new to the Java tools and stuff, so please be gentle.
I see that someone has added the Simple Logging Façade 4 Java (SLF4J) logging capability to a project I am looking at in IntelliJ IDEA. The project is a Gradle project and when I see the Project Structure -> Module -> Dependencies, I do see a dependency for the SLF4 jars.
I also see these listed in the External Libraries node in the treeview in the Project window.
However, when I open the build.gradle file, I see no entry for slfj. How is that? How would this library have been added to the project?
slf4j is a transitive dependency of some other library.
Use ./gradlew dependencies on the root folder of your project to see the dependencies graph.
slf4j ist most likely a transitive dependency of one of the declared dependencies.
To list the dependency tree, you can use gradlew dependencies.
To list the dependency tree for a specific configuration, you can use gradlew dependencies --configuration runtime.
In your situation you can also use the other way around and use dependencyInsight task instead like gradlew dependencyInsight --configuration runtime --dependency org.slf4j:slf4j-api to see which declared dependencies depen on the given dependency in the given configuration.
I have a multi-module maven project that uses some dependencies from netflix. The trouble is that those dependencies are built using gradle and use a runtime scope. When I build my project I then have only the direct dependency loaded but not it's own dependencies.
To fix that I added dependencyManagement entries to transform all the runtime scopes to compile scopes. They usually go in pack of 10 to 20 entries so what I want is to be able to make some pom that would only address this issue and be able to load it any time I need a dependency.
I know this can be done as i've read Maven pull dependencies via middle pom file and How to use POMs as a dependency in Maven? but I was wondering how I may carry those poms inside my current multi-module project.
I'd like to have those in my parent module and avoid needing to create one sub-module per pom. Like pom-dep1.xml, pom-dep2.xml... and have those bundled in my build. Is that possible ?
Thanks
Let's say I have a maven project which has some maven modules inside.
My main module depends on the other modules, so when I compile the main module they should be compiled together.
The question is, how to add these modules as dependencies to the main module?
I know if I have a custom lib that I want to use with maven, let's say a utilities project, I have to compile the jar of the project, do a mvn install:install-file on it to install it on the local repository and then add it to the pom.xml.
Do I have to do this with all my modules and add the dependency to the pom.xml on my main module? Because if it should be done like this, there will be a lot of work to do when changing code on the other modules.
What is the best practice to use avoid the trouble of compiling/installing the modules to local repository?
The question is, how to add these modules as dependencies to the main module?
The same way you add any other dependency to your maven project. By adding group id, artifact id and version to <dependency> element
Do I have to do this with all my modules and add the dependency to the pom.xml on my main module?
If your main module depends on some module A then only the pom of the main module should contain dependency declaration towards module A. You do that for all the dependencies of your module.
I don't know what you mean by "a lot of work when changing the code on other modules". Maven has nothing to do with code changes, it just builds the projects whatever they look like at the given moment...
What is the best practice to use avoid the trouble of compiling/installing the modules to local repository?
Any project that you invoke mvn install on gets built and it's jar copied to local repository. That's all you need to do to get the jar into the repo. This will also put all the dependent jars, if available, into the local repo.
As for best practices for multi module projects:
If your parent project (the one that has modules inside) has <modules> section that lists the modules of your application, and modules are in subdirectories of your parent project, then you simply mvn install (or whatever you want to do) the parent project and that will cause all the modules to be built in order defined by declared dependencies between them. That means that if your main module has dependency on module A, then module A will be built before the main module. This way you can build and install all your modules with one command. On the other hand this approach makes more tight coupling between modules which is not desired in some cases, so it depends on your use case whether it is a good approach or not.
I'm adding jersey to my project:
http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.18.1
do I need to add dependencies to my POM for items found in: "This artifact depends on ..."?
do I need to add dependencies to my POM for items found in: "This
artifact depends on ..."?
No, You don't need to add transitive dependencies. Maven will handle it.
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.
Check here for more details
I have a strange situation. In jar A, I explicitly bring in version 1.3 of commons-dbcp. In jar B, I have a dependency on jar A. However, when I bring in the jar A dependency in jar B, my maven dependency hierarchy shows that jar B is now using 1.4. If I remove that dependency, commons-dbcp is gone from my maven dependency hierarchy so I feel certain it's not being pulled in elsewhere. And when I'm in jar A's maven dependency hierarchy, it only shows 1.3.
Does anyone have any idea why this might be happening?
Maven automatically determines the version to bring in for transitive dependencies. You may have more than one dependency on commons-dbcp (perhaps you're test wouldn't show it if they are in different scope). Use the Maven dependency plugin via mvn dependency:tree to see the other dependencies.