2010-12-22 35 views
6

Khi sử dụng plugin lắp ráp Maven (phiên bản 2.2-beta-5) có vẻ như bình lắp ráp sẽ chứa các tài nguyên từ một phụ thuộc hơn là dự án đang được lắp ráp nếu chúng có cùng đường dẫn. Cụ thể là tôi đang cố gắng tìm ra cách sử dụng tệp cấu hình log4j của dự án chứ không phải là một từ một sự phụ thuộc.Plugin và Tài nguyên Lắp ráp Maven

Project1

-src

--main

--- nguồn

---- log4j.xml

Nếu Project1 có một sự phụ thuộc - gọi nó là Project2 - cũng có tệp log4j.xml trong src/main/resources sau đó sau khi chạy plugin assembly, jar lắp ráp chứa tệp log4j.xml của Project2 thay vì Project1. Tôi tin rằng điều này là bởi vì tất cả các dependencys được giải nén đầu tiên, và do đó, khi nó cố gắng để giải nén dự án cấp cao nhất các tập tin log4j.xml đã có mặt và do đó, nó không được ghi đè.

Có cách nào để plugin lắp ráp sử dụng tệp của dự án thay vì tệp phụ thuộc không?

+0

Câu hỏi có liên quan (tương tự trên thực tế) với chi tiết bổ sung trong câu trả lời của nó: [Lắp ráp maven tùy chỉnh] (http://stackoverflow.com/q/3493381/320399) – blong

Trả lời

1

Một khả năng là loại trừ rõ ràng các tệp có liên quan khỏi quá trình tạo hội đồng.

<dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
      <include>${project.groupId}:Project2</include> 
     </includes> 
     <unpack>true</unpack> 
     <unpackOptions> 
      <excludes> 
       <exclude>**/log4j.xml</exclude> 
      </excludes> 
     </unpackOptions> 
    </dependencySet> 
+1

Điều này phải đi trong quyền lắp ráp? Không có cách nào để chỉ có một tập tin maven pom với điều đúng trong đó. : < – ggb667

3

Something như thế này nên làm việc:

<assembly> 
    <id>without-log4j-config</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
     <dependencySet> 
      <unpack>true</unpack> 
      <scope>runtime</scope> 
      <unpackOptions> 
       <excludes> 
        <exclude>**/log4j.xml</exclude> 
        <exclude>**/log4j.properties</exclude> 
       </excludes> 
      </unpackOptions> 
     </dependencySet> 
    </dependencySets> 
    <files> 
     <file> 
      <source>pom.xml</source> 
      <outputDirectory>/</outputDirectory> 
     </file> 
    </files> 
    <fileSets> 
     <fileSet> 
      <useDefaultExcludes>false</useDefaultExcludes> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
     <fileSet> 
      <directory>src/main/java</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
     <fileSet> 
      <directory>src/main/resources</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
    </fileSets> 
    <moduleSets> 
     <moduleSet> 
      <includeSubModules>false</includeSubModules> 
      <sources> 
       <outputDirectoryMapping>/</outputDirectoryMapping> 
       <excludeSubModuleDirectories>false</excludeSubModuleDirectories> 
       <fileSets> 
        <fileSet> 
         <directory>src/main/java</directory> 
         <outputDirectory>/</outputDirectory> 
        </fileSet> 
        <fileSet> 
         <directory>src/main/resources</directory> 
         <outputDirectory>/</outputDirectory> 
        </fileSet> 
       </fileSets> 
      </sources> 
      <binaries> 
       <dependencySets> 
        <dependencySet> 
         <unpack>true</unpack> 
        </dependencySet> 
       </dependencySets> 
      </binaries> 
     </moduleSet> 
    </moduleSets> 
</assembly> 

Và bạn sẽ cần điều này trong pom của bạn:

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <appendAssemblyId>true</appendAssemblyId> 
       <descriptors> 
        <descriptor>src/main/resources/whatever-you-name-the-snippet-above.xml</descriptor> 
       </descriptors> 
      </configuration> 
     </plugin> 

Đây là một phần quan trọng:

<appendAssemblyId>true</appendAssemblyId> 

Không có nó, nếu bạn chạy mvn assembly:assembly hội đồng tùy chỉnh của bạn sẽ bị ghi đè.

Các vấn đề liên quan