2012-12-05 22 views
8

tôi có cấu hình như sau:Có cách nào để phân chia các tạo phẩm giữa thử nghiệm và biên dịch bằng cách sử dụng plugin phụ thuộc maven trong mục tiêu sao chép phụ thuộc không?

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.6</version> 
    <executions> 
     <execution> 
      <id>analyze</id> 
      <goals> 
       <goal>analyze-only</goal> 
      </goals> 
      <configuration> 
       <failOnWarning>false</failOnWarning> 
      </configuration> 
     </execution> 
     <!--Copy the dependencies so ant build has the same versions--> 
     <execution> 
      <id>copy-dependencies</id> 
      <phase>package</phase> 
      <goals> 
       <goal>copy-dependencies</goal> 
      </goals> 
      <configuration> 
       <outputDirectory>${project.basedir}/lib</outputDirectory> 
       <overWriteIfNewer>true</overWriteIfNewer> 
       <stripVersion>true</stripVersion> 
       <overWriteReleases>false</overWriteReleases> 
       <overWriteSnapshots>true</overWriteSnapshots> 
       <excludeTransitive>false</excludeTransitive> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

Cấu hình trên bãi mọi thứ trên cùng một thư mục. Tôi đã thử loại trừ phạm vi kiểm tra bằng cách thêm cấu hình thử nghiệm nhưng đưa ra một lỗi:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.6:copy-dependencies (copy-dependencies) on project pcgen: Can't exclude Test scope, this will exclude everything.

Có cách nào để tách phụ thuộc kiểm tra khỏi phần còn lại để tôi có thể sao chép vào các thư mục khác nhau không?

+0

Tại sao bạn muốn làm gì? tại sao không sử dụng Maven trực tiếp thay vì Ant? – khmarbaise

+1

Chỉ cần một yêu cầu ngoài tầm kiểm soát của tôi. Ngay bây giờ dự án đang di chuyển từ ANT sang Maven và tôi cần phải giữ cho cả hai hoạt động trong khi quá trình di chuyển hoàn tất. Tôi đang cố gắng tạo lại thiết lập của họ với Maven. – javydreamercsw

Trả lời

8

I tried excluding the test scope by adding the test configuration but gives an error

Tôi chỉ tình cờ gặp vấn đề này, có lẽ vì những lý do rất khác nhau, nhưng tôi nghĩ tôi đã tìm thấy cả hai câu trả lời. Hãy thử điều này, ví dụ. Bạn sẽ cần pom.xml trong thư mục hiện tại, tất nhiên.

mvn dependency:copy-dependencies \ 
-DincludeScope=runtime \ 
-DexcludeScope=provided \ 
-DoutputDirectory=target/war/WEB-INF/lib 

Một lời cảm ơn muộn rất lớn để Brian Fox, người viết trên Maven Dependency Plugin Issue #128:

You shouldn't ever need to include or exclude two scopes at the same time because they are comprised of each other. The default is to include test scope, which includes everything. If you don't want any test dependencies or provided dependencies, then include runtime and exclude provided.

The scopes being interpreted are the scopes as maven sees them, not as specified in the pom. So the "test" scope includes everything, runtime includes compile but not provided etc.

Vào tháng năm 2013, includeScope documentation was updated tới:

/** 
    * Scope to include. An Empty string indicates all scopes (default). 
    * The scopes being interpreted are the scopes as 
    * Maven sees them, not as specified in the pom. In summary: 
    * <ul> 
    * <li><code>runtime</code> scope gives runtime and compile dependencies,</li> 
    * <li><code>compile</code> scope gives compile, provided, and system dependencies,</li> 
    * <li><code>test</code> (default) scope gives all dependencies,</li> 
    * <li><code>provided</code> scope just gives provided dependencies,</li> 
    * <li><code>system</code> scope just gives system dependencies.</li> 
    * </ul> 
    * 
    * @since 2.0 
    */ 
@Parameter(property = "includeScope", defaultValue = "") 
protected String includeScope; 
0

sử dụng includeScope trên thực tế, phạm vi kiểm tra bao gồm tất cả phạm vi, đó là lý do tại sao không thành công.

<includeScope>runtime</includeScope>