2016-07-20 2 views
0

pom.xml에 포함 된 모듈을 어떻게 참조합니까?pom 패키지의 모듈 참조하기

<?xml version="1.0" encoding="UTF-8"?> 
<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.example</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <modules> 
     <module>module1</module> 
     <module>module2</module> 
     <module>module3</module> 
    </modules> 

    <dependencies> 
     <dependency> 
      <groupId>org.codehaus.jettison</groupId> 
      <artifactId>jettison</artifactId> 
      <version>1.3.3</version> 
     </dependency> 
    </dependencies> 

</project> 
+0

: 프로젝트의 모듈을 다른 프로젝트의 종속물로 사용 하시겠습니까? 이 프로젝트가 또 다른 모듈입니까? (즉, 동일한 Aggreator Pom과 동일합니까?) 또는 완전히 분리 된 프로젝트입니까? –

+0

그것은 완전히 별개의 프로젝트입니다. 모든 것은 artifactory에 게시되므로, artifactory는 com.example : parent : 1.0-SNAPSHOT 및 각 모듈을 포함합니다. – bdparrish

답변

0

내가 생각

<dependency> 
    <groupId>com.example</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
</dependency> 

의 pom.xml에게 : 그것은 너무로 다른 프로젝트에서 참조 할 수 있도록 내가이 치어의 모듈을 포함 할 것입니다 방법 아래 참조 pom.xml에서

당신이 할 수있는 최선은 부모 POM의 dependencyManagement 섹션에 서브 모듈을 넣는 것입니다 :

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>module1</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>module2</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>module3</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
    <dependencies> 
</dependencyManagement> 

그러면 각 하위 모듈은 올바른 버전 번호에 대해 걱정할 필요없이 필요한 종속성으로 구성 할 수 있습니다.

<!-- module2's dependencies --> 
<dependencies> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>module1</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>module3</artifactId> 
    </dependency> 
<dependencies> 

모든 하위 모듈을 상위 POM의 종속성으로 선언 한 경우 주기적 종속성이 발생할 수 있습니다. 예 :

[parent] -> [module1] -> [parent] 

Maven은 그렇게하지 않습니다.

관련 문제