2012-11-26 20 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> 
相关问题