SOURCE download
Coordinate
<groupId>com.demo.animal</groupId> <artifactId>animal-core</artifactId> < Version>0.0.1-snapshot</version> <packaging>jar</packaging>
GroupId: Define the actual project that the current MAVEN project belongs to
Artifactid: Defines a MAVEN project (module) in the actual project, and recommends that the actual project project be prefixed with the artifactid, such as: Nexus-indexer
Current version of the Version:maven project
How to Package a Packaging:maven project
Depend on
Pom.xml
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >< Modelversion>4.0.0</modelversion><groupid>com.demo.animal</groupid><artifactid> Animal-core</artifactid><version>0.0.1-snapshot</version><packaging>jar</packaging ><name>animal-core</name><url>http://maven.apache.org</url><properties>< Project.build.sourceencoding>utf-8</project.build.sourceencoding></properties><dependencies ><dependency><groupId>junit</groupId><artifactId>junit</artifactId>< Version>4.10</version><scope>test</scope></dependency><dependency><groupid >org.springframework</groupid><artifactid>spring-core</artifactid><version>3.0.7. Release</version></depenDency><dependency><groupid>org.springframework</groupid><artifactid>spring-beans </artifactId><version>3.0.7.RELEASE</version></dependency><dependency>< Groupid>org.springframework</groupid><artifactid>spring-context</artifactid><version >3.0.7.release</version></dependency><dependency><groupid>org.springframework</ groupid><artifactid>spring-test</artifactid><version>3.0.7.release</version></ Dependency><dependency><groupid>com.kenai.nbpwr</groupid><artifactid>javax-inject </artifactId><version>1.0-201002241208</version></dependency></dependencies>< /project>
Maven uses dependencies by setting coordinates in the dependency element, such as the following:
groupid,artifactid,version: The basic coordinates of dependence, the most important
Type: dependent type, corresponding to the packaging of the project coordinate definition, in most cases, this does not need to be configured, the default feeling jar
Scope: Scope of dependence
Optional: Whether tag dependency is optional
Exclusions: Used to exclude transitive dependencies
Range of dependencies
The dependency range is used to control the relationship with these three classpath (compile classpath, test classpath, execute classpath)
The type of dependency range:
Compile: Compile tie range, default , for compiling, test, execute three kinds of classpath are effective, such as: Spring-core
Test: test-dependent range, only valid for test classpath, such as: JUnit
Provided: The dependency range has been provided, which is effective for compiling and testing classpath, such as: Servlet-api
Runtime: Execution time range, valid for test and execution, such as: JDBC Driver
System: Systems-dependent, same as provided
Dependency range is related to Classpath
Transitive dependency
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd29izw5kawfua3vu/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Execute command to view dependent tree
Dependency:tree
View results:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd29izw5kawfua3vu/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Ways to rely on conflict resolution
Test-a:
SOURCE download
Test-b:
SOURCE download
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd29izw5kawfua3vu/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Install Test-a and test-b to the local warehouse for test-c dependencies
TEST.c
SOURCE download
Why is it dependent on Commons-logging-1.1.3.jar?
Because: when the second direct dependence and the third direct dependence are present, it is preferred to select the second direct dependence (path short)
Go on
Test.d
SOURCE download
Install test-d to the local warehouse. For test-c Dependence
Test-c
SOURCE download
Suppose you need to use Test-b's Commons-logging-1.1.3.jar
Capable of adding exclusions in test-d, for example, the following configuration
<dependency><groupId>com.demo.test</groupId><artifactId>test-d</artifactId>< version>0.0.1-snapshot</version><exclusions><exclusion><groupid>commons-logging< /groupid><artifactid>commons-logging</artifactid></exclusion></exclusions></ Dependency>
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Construction of the project maven slices: 4. Coordination and dependency, spring relies on injection demo