2013-10-16 133 views
2

我正在使用ant-ivy從Maven倉庫中解析依賴項。我使用相同的螞蟻常春藤來發布新的工件到存儲庫中,所以我也在螞蟻中生成.pom文件。從Maven倉庫解決常春藤中的傳遞依賴問題

生成.pom文件是非常簡單的,看起來像這樣(PROJECT_A):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>COMPANY</groupId> 
    <artifactId>PROJECT_A</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0</version> 

    <dependencies> 
     <dependency> 
      <groupId>commons-collections</groupId> 
      <artifactId>commons-collections</artifactId> 
      <version>3.2.1</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-configuration</groupId> 
      <artifactId>commons-configuration</artifactId> 
      <version>1.7</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-lang</groupId> 
      <artifactId>commons-lang</artifactId> 
      <version>2.6</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.16</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.mockito</groupId> 
      <artifactId>mockito-all</artifactId> 
      <version>1.9.5</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

所以它只是在編譯範圍一些依賴和一些測試範圍。現在,該項目(和上面.pom源)我ivy.xml文件看起來是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven"> 
    <info organisation="COMPANY" module="PROJECT_A" revision="1.0" /> 
    <configurations defaultconf="default,sources" defaultconfmapping="sources->sources;%->default"> 
     <conf name="test" visibility="private"/> 
     <conf name="default" description="list of dependencies"/> 
     <conf name="sources" description="source files for all dependencies" /> 
    </configurations> 
    <publications> 
     <artifact type="jar" conf="default" /> 
     <artifact type="sources" ext="jar" m:classifier="sources" conf="sources" /> 
     <artifact type="pom" ext="pom" conf="default" /> 
    </publications> 
    <dependencies> 
     <!-- General --> 
     <dependency org="commons-collections" name="commons-collections" rev="3.2.1" transitive="false"/> 
     <dependency org="commons-configuration" name="commons-configuration" rev="1.7" transitive="false"/> 
     <dependency org="commons-lang" name="commons-lang" rev="2.6" transitive="false"/> 
     <dependency org="log4j" name="log4j" rev="1.2.16" transitive="false"/> 

     <!-- dependencies for junit testing --> 
     <dependency org="junit" name="junit" rev="latest.release" conf="test" /> 
     <dependency org="org.mockito" name="mockito-all" rev="latest.release" conf="test" /> <!-- it's useful by itself, plus it has hamcrest in it which junit needs --> 
    </dependencies> 
</ivy-module> 

再次,很簡單 - 3點的配置,默認了所有的依賴,測試是用於測試的依賴和來源發佈來源。

除了一件事之外,它的一切工作都很好 - 我在PROJECT_A中聲明我的依賴不是傳遞的,然後當我將pom推送到存儲庫時,那些依賴項在範圍編譯中列出。因此,將PROJECT_A作爲依賴項的另一個項目(PROJECT_B)也將擁有PROJECT_A的所有傳遞依賴項,並且我完全不希望這些項目只是希望那些在ivy.xml中明確聲明的項目PROJECT_A。

我試着玩範圍和映射,但它似乎我真的不明白我在那裏做什麼,因爲它沒有任何意義。我想以某種方式修改該方案,以便當我將PROJECT_A作爲依賴項包含時,它將只包含ivy.xml中聲明的PROJECT_A的實際依賴項,因此將會考慮傳遞標誌。

還有一兩件事,我創建.pom文件這樣的:

<ivy:makepom ivyfile="generated-ivy.xml" pomfile="${ant.project.name}.pom" templatefile="${template.pom}" artifactPackaging="jar"> 
    <mapping conf="default" scope="compile" /> 
    <mapping conf="test" scope="test" /> 
</ivy:makepom> 
+1

問題是你發佈到Maven倉庫,所以你必須使用它的元數據格式(POM)。排除傳遞依賴不以同樣的方式工作,我認爲常春藤更靈活。 –

回答

0

馬克的依賴作爲<optional>使其非傳遞。

骯髒的黑客,但這是maven。

相關問題