Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency in Maven

I am really new to maven. I am bit confused about the dependency feature. I know that I can add dependency in the pom file like this

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.6.1</version>
</dependency>

What does this actually mean? Does it mean that I dont need to import the slf4j jar files into my project? If so how does my project get access to those libraries?

I have read about dependency from maven site but didnt help me much.

Can some one explain it in a simpler way.

Thanks

like image 634
Zach Avatar asked Jan 18 '23 03:01

Zach


1 Answers

Nutshell: It means your project has a dependency on slf4j, version 1.6.1.

Furthermore:

  • If you build your project with Maven (or your IDE is Maven-aware), you don't have to do anything else in order to use slf4j. (Aside from normal source-code considerations, like a reasonable import statement, etc.)
  • slf4j v. 1.6.1 will be retrieved from a default Maven repository to your local repository, meaning...
  • ... ~/.m2/repository is your repository. slf4j will be put in $M2_HOME/org/slf4j/$(artifactId}/1.6.1 and will include (in general) a jar file, a pom file, and a hash file.
  • Slf4j's dependencies will be downloaded into your local repository as well.
  • Dependencies of those dependencies will be downloaded ad infinitum/ad nauseum. (The source of "first use of a library downloads the internet" jokes if there are a lot of dependencies; not the case for slf4j.) This is "transitive dependency management"--one of Maven's original purposes.
like image 70
Dave Newton Avatar answered Jan 30 '23 11:01

Dave Newton