2012-11-26 23 views
5

我在我的pom中有兩個名爲A和B的依賴項.A和B都對一個工件C(cassandra-all)具有傳遞依賴性。 A和B使用C的不同版本。依賴項A是神器astyanax

我想保持附帶B.我通過爲C.如何僅排除特定作用域的依賴項?

不幸的是在加入A(Astyanax)排除完成C的,我想B的範圍爲「測試」 。這意味着,如果排除在A中,C將不會包含在測試範圍之外。

我該如何解決這個問題?排除是否僅限於特定範圍?或者,我可以指定哪個版本用於傳遞依賴關係?


例子:
這裏是我的POM樣子:

神器A(astyanax)與神器C相關性的排斥(稱爲卡桑德拉-ALL)

<dependency> 
     <groupId>com.netflix.astyanax</groupId> 
     <artifactId>astyanax</artifactId> 
     <version>1.0.4</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.apache.cassandra</groupId> 
       <artifactId>cassandra-all</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.cassandraunit</groupId> 
     <artifactId>cassandra-unit</artifactId> 
     <version>1.1.1.1</version> 
     <scope>test</scope> 
    </dependency> 

具體而言:當我在測試範圍之外運行代碼並且仍然只保留cassandraunit測試的範圍時,如何包含cassandra-all?

+0

可能的複製[排除了測試行家依賴] (https://stackoverflow.com/questions/12053316/exclude-maven-dependency-for-tests) – Andremoniy

回答

4

我道歉,如果我的問題是不明確的,因爲它可能是。我解決這個問題的方法是不難的:

  • 我在POM添加對C單獨的依賴性
  • 我一直C的排斥一個

具體在這裏,我只是補充:

<dependency> 
     <groupId>org.apache.cassandra</groupId> 
     <artifactId>cassandra-all</artifactId> 
     <version>1.1.5</version> 
    </dependency> 

以及以下依賴項,否則在運行時會丟失。

<dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.6</version> 
    </dependency> 
0

我不確定我是否理解了所有內容,但無論如何,您應該可以通過配置文件實現此目的。

在你的POM,創建用於與B和輪廓B的排斥中,你將有一個依賴與A

排除在運行時,根據其添加相關係數A的輪廓的您選擇的個人資料中會包含一個或另一個。

HIH

0

那麼具體:我怎麼能包括卡桑德拉 - 所有在我的測試範圍之外運行的代碼,仍然只保留cassandraunit測試的範圍是什麼?

Use Maven POM to configure surefire-maven-pluginchange your classpath

如果你想要的僅僅是同時運行測試的cassandra-all依賴從classpath中刪除,那麼下面的POM片段將使棘手:中

<build> 
    <!-- ... --> 

    <plugins> 
    <!-- ... --> 

    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <configuration> 
     <classpathDependencyExcludes> 
      <classpathDependencyExcludes> 
      org.apache.cassandra:cassandra-all 
      </classpathDependencyExcludes> 
     </classpathDependencyExcludes> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 
相關問題