2016-08-11 5 views
1

java 응용 프로그램을 maven으로 마이그레이션하려고합니다. 지금까지 jar 개의 파일로 제공되는 몇 가지 종속성이 있습니다. 이러한 종속성 중 하나는 받는다는 저장소에서 사용할 수 jung2입니다 : mvnrepository.comMaven : pom 유형의 종속성을 가져 오는 방법?

나는 제공된 모든 모듈을 필요로하고 내가 제대로이 실행 종속을 선언하는 방법을 이해 내 pom.xml 등 모든 해당 jar 파일이 다운로드되는 것을하지 않는다 클래스는 컴파일 타임에 사용할 수 있습니다.

이 내 pom.xml 파일이 지금 모습입니다 :

<?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>groupId</groupId> 
    <artifactId>myProject</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <dependencyManagement> 
     <dependencies> 
      <!-- https://mvnrepository.com/artifact/net.sf.jung/jung2 --> 
      <dependency> 
       <groupId>net.sf.jung</groupId> 
       <artifactId>jung2</artifactId> 
       <version>2.0.1</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
</project> 

가 나는 또한 <scope>import</scope>을 떠나 시도하고 dependencies 섹션으로 종속성을 넣어. mvn compile 또는 mvn package을 실행하면 해당 패키지가 존재하지 않는다는 오류 메시지가 발생합니다.

dependencydependencies에 추가하고 dependencyManagement 외부에 추가하면

<dependencies> 
    <dependency> 
    <groupId>net.sf.jung</groupId> 
    <artifactId>jung2</artifactId> 
</dependency> 

누락 된 버전에 대한 오류 메시지가 나타납니다. 그러나 내가 이해하는 한, 이것은 dependencyManagement 때문에 필요하지 않아야합니까? 나는 또한 <version>2.0.1</version>를 추가하면, 나는 다음과 같은 오류 메시지가 얻을 : 당신이 받는다는에서 멀티 모듈 프로젝트가있을 때

Failure to find net.sf.jung:jung2:jar:2.0.1

+0

이것은''섹션 안에 있기 때문에, 그것을 외부에서' '를 추가하거나 의존성 관리에서 제거해야합니다. http://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven?rq=1 – Tunaki

+0

@ Tunaki 답변을 주셔서 감사합니다. 원래 게시물을 편집했습니다. 종속성을'dependencyManager' 외부에 추가하는 것은 지금까지는 작동하지 않았습니다. – yogii

+0

네, 타입을 추가 할 필요가 있습니다 (그리고 어쩌면 스코프, 확실하지 않습니다). – Tunaki

답변

1

는 "dependencyManagement"태그는 일반적으로 사용된다 (당신이 부모 - 자식 관계가있는 곳) .

"dependencyManagement"태그 내에 종속성을 지정하면 가 아닌은 실제로 종속성을 다운로드합니다. 이 태그 내에 종속성을 두는 것은 자식 pom에 대해이 종속성을 다운로드 할 수 있음을 의미합니다. 하위 pom은 groupId와 artifactId를 명시 적으로 제공하여 jar를 다운로드하고 사용하여 해당 클래스를 컴파일해야합니다.

모듈 프로젝트가 하나 뿐인 경우 (귀하의 모듈 프로젝트가 하나 인 것처럼 보이는 경우) 태그를 사용하지 않으면이 문제를 해결할 수 있습니다. 항아리를 태그에 넣기 만하면됩니다. 예를 들어

는 :

<dependencies> 
    <dependency> 
     <groupId>com.abc</groupId> 
     <artifactId>def</artifactId> 
     <version>1.0.0</version> 
     <type>pom</type>  // This will now download the pom and its associated transitive dependent jars 
    </dependency> 
    <dependency> 
     <groupId>com.pqr</groupId> 
     <artifactId>xyz</artifactId> 
     <version>1.0.0</version> 
     <type>pom</type> // This will now download the pom and its associated transitive dependent jars 
    </dependency> 
</dependencies> 

나는 dependenciesManagement 태그는 주로 당신이 당신의 경우가 아니라 멀티 모듈 프로젝트를 가지고있는 경우 감각을 사용하는 것, 전에 말했듯이.