programing

Mavens 종속성 선언 분류 자 ​​속성의 목적은 무엇입니까?

nasanasas 2020. 11. 12. 08:20
반응형

Mavens 종속성 선언 분류 자 ​​속성의 목적은 무엇입니까?


나는 pom.xml 파일을 가지고 있으며 <artifactId>그 차이가 태그 에있는 것과 동일하게 참조되는 3 개의 종속성임을 알 수 있습니다.

<classifier>sources</classifier>
<classifier>javadoc</classifier>

종속성이 SOURCES/JAVADOC하나 뿐인 종속성을 삭제했습니다 . 내 응용 프로그램을 테스트했으며 모든 것이 잘 작동합니다.

이 분류 자 ​​태그를 사용하는 목적은 무엇입니까? <classifier>태그 를 추가하기 위해 종속성을 두 번 복제해야하는 이유 SOURCES/JAVADOC.

<dependency>
   <groupId>oauth.signpost</groupId>
   <artifactId>signpost-commonshttp4</artifactId>
   <version>1.2.1.2</version>
   <type>jar</type>
   <scope>compile</scope>
</dependency>
  <dependency>
   <groupId>oauth.signpost</groupId>
   <artifactId>signpost-commonshttp4</artifactId>
   <version>1.2.1.2</version>
   <type>jar</type>
      ***<classifier>javadoc</classifier>***
   <scope>compile</scope>
</dependency>
<dependency>
   <groupId>oauth.signpost</groupId>
   <artifactId>signpost-commonshttp4</artifactId>
   <version>1.2.1.2</version>
   <type>jar</type>
   ***<classifier>sources</classifier>***
   <scope>compile</scope>
</dependency> 

분류기는 동일한 POM에서 빌드되었지만 내용이 다른 아티팩트를 구별합니다. 존재하는 경우 버전 번호 바로 뒤에 아티팩트 이름에 추가되는 선택적 임의의 문자열입니다.

출처


분류기
의 예이 요소에 대한 동기로 JRE 1.8을 대상으로하는 아티팩트를 제공하는 동시에 JRE 1.7을 계속 지원하는 아티팩트도 제공하는 프로젝트를 고려하십시오. 첫 번째 아티팩트에는 분류 자 ​​jdk18이 장착되고 두 번째 아티팩트에는 jdk14가 장착되어 클라이언트가 사용할 항목을 선택할 수 있습니다.

분류 자의 또 다른 일반적인 사용 사례는 프로젝트의 주요 아티팩트에 보조 아티팩트를 첨부해야한다는 것입니다. Maven 중앙 저장소를 탐색하면 분류 자 ​​소스 및 javadoc이 패키지 된 클래스 파일과 함께 프로젝트 소스 코드 및 API 문서를 배포하는 데 사용된다는 것을 알 수 있습니다.


classifier더 나은 유용성을 이해하는 데 도움이되는 예제에 의한 또 다른 실용적인 대답 .

두 가지 버전의 아티팩트가 필요하다고 가정합니다. for openjpa및 for eclipselink-jar에는 특별히 향상된 JPA 구현에 필요한 엔티티가 포함되어 있기 때문입니다.

Maven 프로필에 정의 된 이러한 빌드에 대해 약간 다른 처리가있을 수 있으며 사용 된 프로필에는 property도 있습니다 <classifier />.

에서 다르게 분류 버전을 빌드하려면 pom(가) maven-jar-plugin다음 followingly 구성 할 것

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <version>3.0.2</version>
   <configuration>
       <classifier>${classifier}</classifier>
   </configuration>
</plugin>

둘 다 설치하면 다음과 같은 repo 파일이 생성됩니다.

org / example / data / 1.0.0 / data-1.0.0.pom
org / example / data / 1.0.0 / data-1.0.0-openjpa.jar
org / example / data / 1.0.0 / data-1.0. 0-eclipselink.jar

이제 classifier어떤 용도 로만 사용 하느냐가 문제 이므로

<dependency>
   <groupId>org.example</groupId>
   <artifactId>data</artifactId>
   <version>1.0.0</version>
   <classifier>[openjpa|eclipselink]</classifier>
</dependency>

It allows distinguishing two artifacts that belong to the same POM but were built differently, and is appended to the filename after the version.

For example if you have other artifacts in your repository (docs, sources ...) you can reference them and add them to your project as dependency. in this code by adding the <classifier>sources</classifier> we are getting the sources.jar from repository.

    <dependency>
    <groupId>oauth.signpost</groupId>
    <artifactId>signpost-commonshttp4</artifactId>
    <version>1.2.1.2</version>
    <type>jar</type>
    ***<classifier>sources</classifier>***
    <scope>compile</scope>
    </dependency> 

actually It lets you locate your dependencies with the further level of granularity.


According to the following: https://blog.packagecloud.io/eng/2017/03/09/how-does-a-maven-repository-work/ classifier tag has implies "Secondary Artifact", which its "transitive dependency" will be cut off! Thus classifier tag not only change "Maven Coordinate" by $artifactId-$version-$classifier.jar!

참고URL : https://stackoverflow.com/questions/20909634/what-is-the-purpose-of-mavens-dependency-declarations-classifier-property

반응형