I've been working with Maven for a little while now and I had a question about the information shown on the Maven Repository site. I was looking at the tags to paste into my pom for spring-web-mvc 3.2.8.RELEASE
and noticed the table with the header "this artifact depends on" and saw the host of artifacts listed below.
My question is simple: Am I supposed to include the all of the dependencies listed in that table in my pom?
When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build.
Force maven to fetch dependencies from the remote repository while building the project. We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository.
In Maven, you declare your project's dependencies in your pom. xml file. Once you've added the dependency into your POM, Maven does the rest. At build time, it downloads the dependency, and makes it available to the build process.
Dependencies are external JAR files (Java libraries) that your project uses. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository. The local repository is just a directory on your computer's hard disk.
To answer your question, no you do not need to include all of the dependencies listed in the artifact dependencies section. It is my understanding that when you include a dependency in your pom
file, maven will automatically download any needed jars. I am inferring this due to the fact that I personally don't add any of the artifact's dependencies other than what I need to my pom
.
For example if I wanted spring-core I would do the following:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
And maven will automatically take care of the dependencies for me.
A good way to test this out is to open a new maven project in eclipse and specify a dependency such as this, update the project, and then check in the Maven dependencies folder.
For fun, I experimented with this and it is indeed true, Maven will download any necessary dependencies when you update your project. After putting only the above dependency in my pom.xml
file I got the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With