2016-06-06 2 views
0

pom.xml에 모든 종속성 목록과 해당 버전이 포함 된 파일을 인쇄하고 싶습니다. (각 종속성 내부에 갈 필요가 없음)pom.xml에서 종속성 정보 수집

내 궁극적 인 목표는 런타임에 응용 프로그램에서 읽을 수 있고 웹의 "버전 정보"링크를 통해 표시 할 수있는 종속성 + 버전 정보 목록을 파일에 포함시키는 것입니다 페이지.

maven dependecy plugin | dependency:list이 있는데, 내가 알고있는 바에는 내가 원하는 것을 거의해야한다는 것을 알게되었습니다. 또한 출력 파일을 인쇄하기 위해 관리하지만 주로 횡설수설을 포함합니다. 내가 이해할 수있는 것은 프로젝트의 패키지 목록을 가지고있는 것입니다. (버전 정보 없음)

누군가가이 플러그인을 올바르게 사용하는 방법을 명확히 설명해 주시고 또는 내가 필요로하는 것이 무엇인지 명확하게 설명해주십시오. My configuration은 사용법과 동일하지만 선택적 매개 변수를 사용하려고하면 항상 실패합니다.

답변

0

이제 제대로 된 것처럼 보입니다. 버전 파일은 'target/classes'에 인쇄되며 런타임에 앱을 볼 때 찾을 수 있습니다.

의 pom.xml에서

(빌드/플러그인) : 가정으로

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.10</version> 
    <executions> 
     <execution> 
      <id>createVersionInfo</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>list</goal> 
      </goals> 
      <configuration> 
       <artifactItems> 
        <artifactItem> 
         <groupId>com.company.project</groupId> 
         <artifactId>app-name</artifactId> 
         <version>${project.version}</version> 
         <type>war</type> 
         <overWrite>true</overWrite> 
        </artifactItem> 
       </artifactItems> 
       <sort>true</sort> 
       <includeScope>compile</includeScope> 
       <outputFile>target/classes/dependency_versions.txt</outputFile> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

'<excludeScope> 테스트 </excludeScope >'는 작동하지 않습니다. 그것은 모든 것을 배제합니다. 나는 에 대한 설명을 includeScope이 어떻게 든 설명한다고 생각합니다.

빈 문자열은 모든 범위 (기본값)를 나타냅니다. 해석되는 범위는 Maven에서 볼 수있는 범위 ( )가 pom에 지정된 것과 다릅니다. 요약 : 나는 실제로 내 자신의 목록을 채우는하고

InputStream in = this.getClass().getResourceAsStream("/dependency_versions.txt"); // Finds the file from classpath 
String content = ""; 
// Java7 AutoCloseable 
try (Scanner scan = new Scanner(in)) { 
    scan.useDelimiter("\\Z"); // Found this from another SO-thread, enables to read in the whole file at once 
    content = scan.next(); 
} 
// Iterate the content and collect the information 
// \n = line change 
for (String row : content.split("\n")) { 
    row = row.trim(); 
    // Basically removes the 1st two lines of the file that are not wanted 
    if (StringUtils.isEmpty(row) || row.endsWith(":")) { 
     continue; 
    } 
    StringTokenizer tokenizer = new StringTokenizer(row, ":"); 
    String package = tokenizer.nextToken(); 
    String dependency = tokenizer.nextToken(); 
    String type = tokenizer.nextToken(); 
    String version = tokenizer.nextToken(); 
    String scope = tokenizer.nextToken(); 
} 

을 보여주는 거기 TO :

runtime - scope gives runtime and compile dependencies, 
compile - scope gives compile, provided, and system dependencies, 
test  - (default) scope gives all dependencies, 
provided - scope just gives provided dependencies, 
system - scope just gives system dependencies. 

그리고 자바 측이 코드 조각을 거의 필요로 무엇을 할 것인가 JSF에서 정보를 얻지 만 간결함과 가독성을 위해이 부분을 생략했습니다.

... 실제로 내가 왜 전체 파일을 한 번에 읽고 반복하지 않고 한 번에 한 줄씩 읽으려고하는지 생각하게 만들었지 만 일일 WTF로 남겨 두겠다. ;)