Gradle Transitive Dependency问题本地常春藤

时间:2017-03-15 14:31:22

标签: java gradle ant ivy

我正在将ivy + ant项目转换为gradle并且我创建了build.gradle文件,该文件引用了projectA(下载了它的jar),但projectA中列出的依赖项未在我的项目中下载

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'


repositories {

     ivy  {
        url 'http://ivyrepodomain:8080/repo'
        layout 'pattern', {
              artifact 'snapshot/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]'
              artifact '3rd-party/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]'
              artifact 'b2bdev/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]'
              ivy '3rd-party/[organisation]/[module]/ivys/ivy-[revision].xml'
              ivy 'snapshot/[organisation]/[module]/ivys/ivy-[revision].xml'
        }
    }

}
targetCompatibility = sourceCompatibility = JavaVersion.VERSION_1_6

dependencies {


    testCompile('mygroup:projectA:17.20.SNAPSHOT') {
        exclude group: 'org.apache.wicket'
        exclude group: 'org.wicketstuff'
    }
    testCompile('org.hibernate.common:hibernate-commons-annotations:4.0.1.Final') {
        transitive = false
    }
    testCompile('org.hibernate:hibernate-ehcache:4.1.2.Final') {
        transitive = false
    }
    testCompile('org.javassist:javassist:3.16.1-GA') {
        transitive = false
    }
    compileOnly('javax.servlet:javax.servlet-api:3.0.1') {
        transitive = false
    }
    compileOnly('dom4j:dom4j:1.6.1') {
        transitive = false
    }
    testCompile('mygroup:projectA:17.20.SNAPSHOT') {
        exclude group: 'org.apache.wicket'
        exclude group: 'org.wicketstuff'
    }
    testCompile('com.h2database:h2:1.4.187') {
        transitive = false
    }
    testCompile('org.apache.derby:derby:10.11.1.1') {
        transitive = false
    }
    testCompile('org.hsqldb:hsqldb:2.3.4') {
        transitive = false
    }
}

项目A有一些依赖关系,如下面的ivy-17.20.SNAPSHOT.xml(托管在ivy repo上)文件

<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="mygroup" module="projectA" revision="17.20.SNAPSHOT" status="integration" publication="434334345"></info>
<configurations>
<conf name="test" visibility="public" description="Dependencies needed only for testing"/>
<conf name="compile" visibility="public" description="Dependencies required for compile time that are not provided by a container"/>
<conf name="runtime" extends="compile" visibility="public" description="Dependencies not needed for compile time but are needed for runtime"/>
<conf name="provided" visibility="public" description="Dependencies provided by a container"/>
<conf name="ear" visibility="public" description="Dependencies managed by ear level classloader"/>
<conf name="war" visibility="public" description="Dependencies managed by war level classloader"/>
<conf name="default" visibility="public"/>
<conf name="optional" visibility="public"/>
<conf name="sources" visibility="public"/>
</configurations>
<publications>
<artifact name="projectA"/>
<artifact name="projectA-sources" type="src" ext="jar" conf="sources"/>
</publications>
<dependencies>

<!--  Spring and related dependencies  -->
<dependency org="org.springframework" name="spring-core" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-context" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-web" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-beans" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-expression" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-aop" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-orm" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-tx" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-jdbc" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-test" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-context-support" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework" name="spring-oxm" rev="4.1.6.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.data" name="spring-data-neo4j" rev="2.1.0.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.data" name="spring-data-neo4j-tx" rev="2.1.0.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.batch" name="spring-batch-core" rev="2.1.8.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.batch" name="spring-batch-infrastructure" rev="2.1.8.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.security" name="spring-security-core" rev="3.2.4.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.security" name="spring-security-web" rev="3.2.4.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.security" name="spring-security-config" rev="3.2.4.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.security" name="spring-security-ldap" rev="3.2.4.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.springframework.ldap" name="spring-ldap" rev="1.3.0.RELEASE" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.apache.velocity" name="velocity" rev="1.7" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="aopalliance" name="aopalliance" rev="1.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.microsoft.sqlserver" name="sqljdbc" rev="4.0.2206.100" transitive="false" conf="provided->default"/>
<dependency org="com.ibm.db2" name="db2jcc" rev="3.62.56" conf="provided->default"/>
<dependency org="com.ibm.db2" name="db2jcc_license" rev="1.0" conf="provided->default"/>
<dependency org="org.apache.commons" name="commons-lang3" rev="3.1" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-lang" name="commons-lang" rev="2.6" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-beanutils" name="commons-beanutils" rev="1.8.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-dbcp" name="commons-dbcp" rev="1.2.2" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-pool" name="commons-pool" rev="1.5.2" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-collections" name="commons-collections" rev="3.2" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-io" name="commons-io" rev="1.4" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-httpclient" name="commons-httpclient" rev="3.1" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="commons-codec" name="commons-codec" rev="1.6" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.google.guava" name="guava" rev="16.0.1" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.yammer.metrics" name="metrics-core" rev="2.2.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.yammer.metrics" name="metrics-annotation" rev="2.2.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.yammer.metrics" name="metrics-servlet" rev="2.2.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.yammer.metrics" name="metrics-web" rev="2.2.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.yammer.metrics" name="metrics-spring" rev="2.2.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.yammer.metrics" name="metrics-logback" rev="2.2.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.apache.wicket" name="wicket-core" rev="1.5.13" transitive="false" conf="compile->default; war->default"/>
<dependency org="org.apache.wicket" name="wicket-ioc" rev="1.5.13" transitive="false" conf="compile->default; war->default"/>
<dependency org="org.apache.wicket" name="wicket-spring" rev="1.5.13" transitive="false" conf="compile->default; war->default"/>
<dependency org="org.apache.wicket" name="wicket-util" rev="1.5.13" transitive="false" conf="compile->default; war->default"/>
<dependency org="org.apache.wicket" name="wicket-request" rev="1.5.13" transitive="false" conf="compile->default; war->default"/>
<dependency org="org.hibernate" name="hibernate-core" rev="4.1.2.Final" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.hibernate.javax.persistence" name="hibernate-jpa-2.0-api" rev="1.0.1.Final" transitive="false" conf="provided->default"/>
<dependency org="org.hibernate" name="hibernate-validator" rev="4.1.0.Final" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.jasypt" name="jasypt" rev="1.9.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.jasypt" name="jasypt-hibernate4" rev="1.9.0" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="net.sf.ehcache" name="ehcache-core" rev="2.5.1" transitive="false" conf="compile->default; ear->default"/>
<dependency org="ch.qos.logback" name="logback-core" rev="1.0.9" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.9" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.2" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.7.2" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="org.slf4j" name="log4j-over-slf4j" rev="1.7.2" conf="compile->default; war->default; ear->default" transitive="false"/>
<dependency org="cglib" name="cglib-nodep" rev="2.1_3" transitive="false" conf="compile->default; war->default; ear->default"/>
<dependency org="com.rsa" name="axm-runtime-api" rev="6.1" conf="compile->default; war->default; ear->default" transitive="false"/>
<dependency org="com.rsa" name="jsafeJCE" rev="3.5.2" conf="runtime->default; war->default; ear->default" transitive="false"/>
<dependency org="junit" name="junit" rev="4.11" conf="compile->default;test->default" transitive="false"/>
<dependency org="javax.servlet" name="javax.servlet-api" rev="3.0.1" conf="provided->default" transitive="false"/>
<dependency org="javax.transaction" name="jta" rev="1.1" conf="provided->default" transitive="false"/>
<dependency org="org.unitils" name="unitils-core" rev="3.4.2" conf="compile->default;test->default" transitive="false"/>
<dependency org="org.unitils" name="unitils-database" rev="3.4.2" conf="compile->default;test->default" transitive="false"/>
<dependency org="org.unitils" name="unitils-dbunit" rev="3.4.2" conf="compile->default;test->default" transitive="false"/>
<dependency org="org.unitils" name="unitils-orm" rev="3.4.2" conf="compile->default;test->default" transitive="false"/>
<dependency org="org.unitils" name="unitils-spring" rev="3.4.2" conf="compile->default;test->default" transitive="false"/>
<dependency org="org.dbunit" name="dbunit" rev="2.4.8" conf="compile->default;test->default" transitive="false"/>
<dependency org="org.mockito" name="mockito-all" rev="1.9.0" conf="compile->default;test->default" transitive="false"/>
</dependencies>
</ivy-module>

请帮助解决这个问题 感谢

1 个答案:

答案 0 :(得分:1)

本教程中给出了单个常春藤模块多项目gradle build https://gist.github.com/BorePlusPlus/4145778

完整示例

有一个完整的演示示例,即使用多项目构建进行发布:https://docs.gradle.org/current/userguide/publishing_ivy.html#publishing_ivy:example

希望这将为多项目澄清您的常春藤和gradle组合。

您还需要添加

apply plugin: 'ivy-publish'

那是你未在build.gradle文件中添加的那个。

有关更多信息,请参阅本教程:Getting Started With Gradle: Creating a Multi-Project Build

更新#1:

我在github https://github.com/rizvi/java-multi-project

中创建了一个项目

克隆项目并运行以下2命令

  1. gradle clean
  2. gradle jar
  3. 控制台

    mac@My-PC:~/Desktop/gradleproject/java-multi-project$ gradle jar
    :project2:compileJava UP-TO-DATE
    :project2:processResources UP-TO-DATE
    :project2:classes UP-TO-DATE
    :project2:copyToLib
    :project2:jar
    :project1:compileJava UP-TO-DATE
    :project1:processResources UP-TO-DATE
    :project1:classes UP-TO-DATE
    :project1:copyToLib
    :project1:jar
    
    BUILD SUCCESSFUL
    
    Total time: 20.337 secs
    
    This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
    

    这将创建2个项目。他们是

    i)project1

    ii)project2

      

    在project1 / build / lib文件夹中,您将获得   commons-collections-3.2.2.jarhamcrest-core-1.3.jar,   junit-4.12.jarproject2-1.0.jar

         

    在project2 / build / lib文件夹中,您将获得   仅commons-collections-3.2.2.jar

    这里project1依赖于project2。所以project1包含project2的jar文件和相关的jar文件。

    希望它能满足您的需求。 :)

    更新#2:

    有一个由gradle-ivyxml-plugin命名的插件。但它有各种类型的障碍。它们在下面给出。

    1. 故意不对任何ivysettings.xml文件执行任何操作。
    2. 有目的地忽略与发布相关的ivy.xml元素和 属性。
    3. UNSUPPORTED ivy.xml功能

      支持大多数ivy.xml元素和属性。在这里,我们记录那些不是。

      忽略以下ivy.xml元素和属性。我尽力检测并支持,抛出或警告,但公共Ivy API不允许访问这些设置。

      <conflicts> (and all attrs and sub-elements)
      <dependencies><dependency><conf>  (For conf-mapping)
      <dependencies><dependency><artifact conf="...">  attr.
      <dependencies><dependency><*><conf>
      

      故意禁止使用以下元素和属性。我们不支持他们,然后默默地忽略它们会产生误导,我们可以检测它们的使用情况。

      <dependencies><dependency><exclude artifact="..." type="..."
          ext="..." matcher="..." cont="..."
          (i.e. only 'org' and 'module' attrs are supported).
      <dependencies><override>
      <dependencies><dependency branch="..." force="..."  attrs.
       (Branch and force have no support in Gradle).
      

      资源链接:

      https://github.com/unsaved/gradle-ivyxml-plugin/tree/master/doc

      此处提供了定制的最低解决方案:

      1. http://technicallypossible.blogspot.com/2009/12/using-ivyxml-with-gradle.html