removing unwanted jars pom.xml automatically downloads - maven

In my pom.xml ,even though i have not declared a dependency for commons logging and slf4j i can see them being automatically getting downloaded by maven.Is there a way to specify globally in pom.xml for the exclusion of these jars?

This is because your included a dependency in your pom.xml which is dependent on commons logging and sl4j. This is transitive dependency mechanism used by maven.
Go to Dependency Heirarchy Tab in eclipse to find out which dependency is downloading the logging dependencies.
Then you need use the <exclusions>{dependency}</exclusions> to exclude the dependency.
This maven page has good information on how to exclude transitive dependencies.

Related

I have big project in IntelliJ IDEA(UE) and list of External Libraries. How can I find where in the project I add this lib from the maven?

I have jackson-core-2.9.0 in the list of External Libraries, but I cant find where I added this lib in the project
You must understand how maven dependency works.
If you add any dependency to your pom.xml which is direct dependency to your project.
Then those direct dependencies have direct dependencies of their own and those dependencies have direct dependencies of their own and so on until there are no direct dependencies, these are called transitive dependencies of your project.
Use mvn dependency:tree to display all you your dependencies in tree structure to find which direct dependency has jackson-core-2.9.0 as dependency.
Note: more than one direct dependency can have jackson-core-2.9.0(or any other dependency) as dependency

writing pom.xml for maven dependencies sharing same dependency

I am creating my custom-exception dependency which uses org.springframework.web as its dependency.
so I will be using custom-exception as dependency in a master-project which also has org.springframework.web as one of its dependency.
so my concern is how do i write pom.xml file for custom-exception so that I can include it in master-project without getting any conflicts.
Any extra information regarding dependency versioning and scope will be appreciated.
This is the first time I am creating maven dependency

Maven copy-dependencies: not all dependencies copied?

This question is about Maven. My project has spring-boot-starter-parent as its parent. Mvn Repository's link, shows that through all parent hierarchies, spring-boot-starter-parent has 273 dependencies in total.
However, when I run the goal dependency:copy-dependencies, I get only a handful of jars, and in particular, I notice that javassist is not one of the jars. Why aren't the jars for all 273 dependencies copied by dependency:copy-dependencies? Can Maven somehow tell if some of these dependencies are not needed by my project?
There are 273 managed dependencies in spring-boot-starter-parent. Managed dependencies are just there to give maven details about libraries your project uses when it needs it. They are not actually included in your project when it gets built. The dependencies included are those in your project's <dependencies> section and their transitive dependencies. Hence the difference you see.

Pom.xml downloading unmentioned dependencies

I have a simple pom.xml which have only JUnit dependency and exec-maven-plugin.
But when I say "mvn install" I see lot of dependencies downloading.
Are this mandatory dependencies by maven?
I am listing a few here :
ClassWorlds
Commons-logging-api
log4j
backport-util-concurrent
Are this mandatory dependencies by maven
Yes, those are transitive dependencies.
This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically
See "Resolving conflicts using the dependency tree"
A project's dependency tree can be expanded to display dependency conflicts. For example, to find out why Commons Collections 2.0 is being used by the Maven Dependency Plugin, we can execute the following in the project's directory:
mvn dependency:tree -Dverbose -Dincludes=commons-collections

Netbeans: maven dependencies of type pom

I've spent a lot of time and my head is blowing up already so I'll be very thankful for any help.
I'm migrating Netbeans Platform application from ant to maven, and so I'm changing all the jars in my version control repo to maven dependencies. I've found needed artifact in main maven repo and I've added it as a dependency with a help of Netbeans, but it's of type POM and was placed in Non-classpath Dependencies and I have no idea how to use it as it wasn't added to classpath etc…
Can someone explain what are these POM dependencies and how to use them?
Thank you in advance!!
EDIT
here is dependency definition in pom.xml
<dependency>
<groupId>com.kitfox.svg</groupId>
<artifactId>svg-salamander</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
Adding a pom dependency only pulls down transitive dependencies, that is jar dependencies defined as dependencies in the pom. The pom does not get added on the classpath for obvious reasons, but the transitive dependencies reachable from pom will be added to classpath.
What you ideally need to do is have dependencies of type jar Default dependency type is jar and you can simply define dependencies without any type element in the dependency section.
If you have located the jar files you need in Maven Cental, then you simply need to provide groupId artifactId and version for each one of those in dependencies section.
Personally I cannot think of any case when one would need to add pom type dependency. I usually use pom packaging for parent module in a project (specify common project configuration like plugin versions, common dependencies, like log4j for example, repositories, properties etc.) and for utility package module (the one that assembles the project and does some other necessary things).
Judging from my experience (I did it several times), when migrating project from ant to maven you should take all the jar files that your project used to depend on and convert them into maven dependencies (groupId:artifactId:version). Most probably all of these dependencies will not have any <type> (e.g. be jars).

Resources