Maven - Manage Dependencies
Transitive Dependencies Discovery
Feature | Description |
---|---|
Dependency mediation | Determines what version of a dependency is to be used when multiple versions of an artifact are encountered. If two dependency versions are at the same depth in the dependency tree, the first declared dependency will be used. |
Dependency management (의존관계 관리) | Directly specify the versions of artifacts to be used when they are encountered in transitive dependencies. For an example project C can include B as a dependency in its dependencyManagement section and directly control which version of B is to be used when it is ever referenced. |
Dependency scope (의존관계 범위) | Includes dependencies as per the current stage of the build (현재 빌드 단계에 따라 의존관계들을 포함한다.) |
Excluded dependencies | Any transitive dependency can be excluede using "exclusion" element. As example, A depends upon B and B depends upon C then A can mark C as excluded. |
Optional dependencies (선택적인 의존관계들) | Any transitive dependency can be marked as optional using "optional" element. As example, A depends upon B and B depends upon C. Now B marked C as optional. Then A will not use C. |
Dependency Scope
Scope | Description |
---|---|
compile | This scope indicates that dependency is available in classpath of project. It is default scope. |
provided | This scope indicates that dependency is to be provided by JDK or web-Server/Container at runtime |
runtime | This scope indicates that dependency is not required for compilation, but is required during execution. |
test | This scope indicates that the dependency is only available for the test compilation and execution phases. (이 범위는 의존관계가 단지 테스트 컴파일과 실행 단계에서 가능함을 나타낸다.) |
system | This scope indicates that you have to provide the system path. |
import | This scope is only used when dependency is of type pom. This scopes indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. |
Dependency Management
- App-UI_WAR는 APP-Core-lib와 App-Data-lib를 의존한다.
- Root는 App-Core-Lib와 App-Data-lib의 부모이다.
- Root는 의존관계 섹션에 의존관계로써 Lib1, lib2, Lib3 fmf wjddmlgksek.
App-UI-WAR
<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.companyname.groupname</groupId> <artifactId>App-UI-WAR</artifactId> <version>1.0</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.companyname.groupname</groupId> <artifactId>App-Core-lib</artifactId> <version>1.0</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>com.companyname.groupname</groupId> <artifactId>App-Data-lib</artifactId> <version>1.0</version> </dependency> </dependencies> </project>
App-Core-lib
<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"> <parent> <artifactId>Root</artifactId> <groupId>com.companyname.groupname</groupId> <version>1.0</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.groupname</groupId> <artifactId>App-Core-lib</artifactId> <version>1.0</version> <packaging>jar</packaging> </project>
App-Data-lib
<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"> <parent> <artifactId>Root</artifactId> <groupId>com.companyname.groupname</groupId> <version>1.0</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.groupname</groupId> <artifactId>App-Data-lib</artifactId> <version>1.0</version> <packaging>jar</packaging> </project>
Root
<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.companyname.groupname</groupId> <artifactId>Root</artifactId> <version>1.0</version> <packaging>pom</packaging> <dependencies> <dependency> <groupId>com.companyname.groupname1</groupId> <artifactId>Lib1</artifactId> <version>1.0</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>com.companyname.groupname2</groupId> <artifactId>Lib2</artifactId> <version>2.1</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>com.companyname.groupname3</groupId> <artifactId>Lib3</artifactId> <version>1.1</version> </dependency> </dependencies> </project>
이제 App-UI-WAR 프로젝트를 빌드할 때 Maven은 의존관계 그래프를 가로지는 것으로 모든 의존관계를 발견할 것이고 프로그램을 빌드할 것이다.
위의 예로부터, 몇가지 중요 개념을 배울 수 있다.
- 곤통 의존관계는 부모 pom의 개념을 사용하여 단일 공공에 위치시킬 수 있다. App-Data-lib와 App-Core-lib 프로젝트의 의존관계들은 Root 프로젝트에서 list되어 진다.(Root의 패키징 타입을 보자. 이것은 POM 이다.)
- App-UI-WAR에서 의존관계로써 Lib1, lib2, Lib3를 녕시할 필요가 없다. Maven은 그같은 상세를 관리하기 위해 추의적 의존관계 매커니즘을 사용한다.