为什么Gradle不包含必需的依赖项?

时间:2016-04-12 15:25:00

标签: java spring maven gradle dependencies

环境:Linux,Artifactory,Java Web应用程序,带有Spring依赖管理插件的Gradle 2.12和Flyway插件。

我们不使用Artifactory插件。我们只是把它当作一个通用的maven存储库。

项目规模庞大,有80到90个子项目。我们有几个人正在努力从Maven迁移它,但是有很多令人头疼的问题。我们击败了他们中的大部分,但是这一系列的结很接近我们。

问题:

  1. 使用--daemon而非--parallel构建并不比Maven快。这看起来很奇怪。分析表明依赖性解析需要很长时间。
  2. 构建的某些方面不稳定。这就是说,当我们尝试构建时,我们会遇到各种编译器问题。无论我们是否使用--parallel,都会发生这种情况,尽管--parallel会更大程度地发生这种情况。无论本地或远程依赖性如何,它也会发生。我们怀疑它与依赖解析的某些方面有关,或者可能是Gradle部分意外排除行为的结果。具体来说,我们得到" Class def not not"和/或"缺少符号"。通常这似乎与传递依赖有关。如果我明确地把它放进去,那么错误就会消失,我会得到一个与另一个传递有关的新错误。我已尝试将它们作为传递和transitive = false进行实验。
  3. 使问题复杂化,我们有很多BOM。也许10?有些是我们的,有些属于第三方。两个或三个超过一页的长度。
  4. 如果没有--parallel我们似乎无法获得证明迁移合理性所需的性能,但我们可能会幸免于此并等待--parallel完成孵化 IF < / em>我们可以让它可靠地构建。我们已经在--debug骑了大约两个星期了,但我们的店铺自然缺乏Groovy和Gradle经验。

    澄清:大约30%的时间用--parallel,大约90%没用。如果您构建有问题的特定项目,使用完整的项目路径或更改到该子目录,则构建没有问题。

    例如,从--debug输出中,我看到:

    ...
    -classpath 
    /development/.../build/classes/main
    /development/.../build/resources/main
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/4.1.7.RELEASE/8c6c02bcccfa23a74db59f7b7725e69e1af38f04/spring-context-4.1.7.RELEASE.jar
    /development/.../build/libs/data-6.7.0-SNAPSHOT.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-core/4.2.18.Final/2b4c72104fe1910d368d766243f0d0ac2608e134/hibernate-core-4.2.18.Final.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/joda-time/joda-time/2.8.1/f5bfc718c95a7b1d3c371bb02a188a4df18361a9/joda-time-2.8.1.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/commons-lang/commons-lang/2.6/ce1edb914c94ebc388f086c6827e8bdeec71ac2/commons-lang-2.6.jar
    /development/.../build/libs/pnq-orgmanagement-6.7.0-SNAPSHOT.jar
    /development/.../build/libs/pnq-stuffmanagement-6.7.0-SNAPSHOT.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/com.pnq/pnq-someutils/6.7.0-SNAPSHOT/642a90ae7cc4f3f9b281184cacbfa1294f176df8/pnq-someutils-6.7.0-SNAPSHOT.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/com.eaio.stringsearch/stringsearch/2/44618501b2fb6b2d1bb851d00b264a6eaf1fc0b0/stringsearch-2.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.52/88a941faf9819d371e3174b5ed56a3f3f7d73269/bcprov-jdk15on-1.52.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/commons-collections/commons-collections/3.2.1/761ea405b9b37ced573d2df0d1e3a4e0f9edc668/commons-collections-3.2.1.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.10/4b95f4897fa13f2cd904aee711aeafc0c5295cd8/commons-codec-1.10.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/4.1.7.RELEASE/e52148e9671e2918a2172c9cf56b77bede2042ce/spring-beans-4.1.7.RELEASE.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/commons-validator/commons-validator/1.4.1/2231238e391057a53f92bde5bbc588622c1956c3/commons-validator-1.4.1.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/4.1.7.RELEASE/d8923bdffe631904899875e719d8b363bc3deaea/spring-orm-4.1.7.RELEASE.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.javolution/javolution-core-java/6.2.0rc3/5bae18008a0182d80155dbbe2c91d8907d2496d/javolution-core-java-6.2.0rc3.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/4.1.7.RELEASE/3465a5d3b24006d51482cf45abd13e347f64582a/spring-tx-4.1.7.RELEASE.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.6.1/6f3b8a24bf970f17289b234284c94f43eb42f0e4/slf4j-api-1.6.1.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/com.pnq/pnq-batchutils/6.7.0.2/9c025552239645478a759267748c73f3e1e43a47/pnq-batchutils-6.7.0.2.jar
    /development/.../build/libs/pnq-mailutils-6.7.0-SNAPSHOT.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/com.pnq/pnq-utilities/6.7.0.2/d1e8ad707ebd2eddbb29eb0052c05b34acd98b46/pnq-utilities-6.7.0.2.jar
    /development/.../build/libs/pnq-database-6.7.0-SNAPSHOT.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/com.twilio.sdk/twilio-java-sdk/3.3.9/133f7bde99aefae1df78ecd9787e5e60bc521ad2/twilio-java-sdk-3.3.9.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.apache.velocity/velocity/1.7/2ceb567b8f3f21118ecdec129fe1271dbc09aa7a/velocity-1.7.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/javax.mail/mail/1.4.1/8b7bc69010655425dabf091b51d1e90b4de36715/mail-1.4.1.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5/a1e6cbb3cc2c5f210dd1310ff9fcb2c09c0d1438/httpclient-4.5.jar
    /development/.../build/libs/pnq-infoassembler-6.7.0-SNAPSHOT.jar
    /development/.../build/libs/pnq-stufflookup-6.7.0-SNAPSHOT.jar
    /home/someUser/.gradle/caches/modules-2/files-2.1/com.pnq/pnq-rcrtrlss/6.7.0-SNAPSHOT/58d6caa20da9035ce7b311f54915448c5bb903dc/pnq-wierdorules-6.7.0-SNAPSHOT.jar
    /development/.../build/libs/pnq-cmanagement-6.7.0-SNAPSHOT.jar
    /development/.../build/libs/pnq-translation-6.7.0-SNAPSHOT.jar
    /development/.../build/libs/pnq-eutilities-6.7.0-SNAPSHOT.jar
    /development/.../build/libs/pnq-control-6.7.0-SNAPSHOT.jar
    /development/../database/build/libs/test-pnq-database-6.7.0-SNAPSHOT.jar 
    ...
        14:50:06.439 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] junit:junit is excluded from com.project:project-enterprise-test:6.7.0.2(default).
        ...
            st.java:3: error: package org.junit does not exist
            14:50:06.481 [ERROR] [system.err] import static org.junit.Assert.assertEquals;
            14:50:06.481 [ERROR] [system.err]                        ^
    

    注意:全局搜索显示Gradle构建中的任何位置junit都没有排除。另外,我在-classpath看到了什么 DON&#39; T ? Junit的。 ...但在我看到的相关build.gradle文件中:

    testCompile ("com.project:project-enterprise-test")
    

    以上是包含Maven依赖关系的BOM:

    <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
          <groupId>com.oracle</groupId>
          <artifactId>ojdbc7</artifactId>
        </dependency>
        <dependency>
          <groupId>org.dbunit</groupId>
          <artifactId>dbunit</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-pool2</artifactId>
        </dependency>
        <dependency>
          <groupId>org.easymock</groupId>
          <artifactId>easymock</artifactId>
          <exclusions>
            <exclusion>
              <groupId>cglib</groupId>
              <artifactId>cglib-nodep</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.mockito</groupId>
          <artifactId>mockito-core</artifactId>
          <exclusions>
            <exclusion>
              <groupId>org.hamcrest</groupId>
              <artifactId>hamcrest-core</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-integration</artifactId>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jul-to-slf4j</artifactId>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </dependency>
        <dependency>
          <groupId>joda-time</groupId>
          <artifactId>joda-time</artifactId>
        </dependency>
        <dependency>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-all</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-dbcp2</artifactId>
        </dependency>
        <dependency>
          <groupId>org.fitnesse</groupId>
          <artifactId>fitlibrary</artifactId>
        </dependency>
        <dependency>
          <groupId>javax.transaction</groupId>
          <artifactId>jta</artifactId>
        </dependency>
        <dependency>
          <groupId>javax.ws.rs</groupId>
          <artifactId>jsr311-api</artifactId>
        </dependency>
        <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-bundle</artifactId>
        </dependency>
        <dependency>
          <groupId>net.sf.dbfit</groupId>
          <artifactId>dbfit</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-jexl</artifactId>
        </dependency>
        <dependency>
          <groupId>commons-beanutils</groupId>
          <artifactId>commons-beanutils</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>com.springsource.org.apache.commons.io</artifactId>
        </dependency>
        <dependency>
          <groupId>javax.jms</groupId>
          <artifactId>jms</artifactId>
        </dependency>
        <dependency>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </dependency>
        <dependency>
          <groupId>net.servicefixture</groupId>
          <artifactId>servicefixture</artifactId>
        </dependency>
      </dependencies>
    

    在根build.gradle中:

    dependencyManagement {
        ...
        imports {
          mavenBom "com.project:project-enterprise-test:$bomversion"
        }
        ...
      }
    

1 个答案:

答案 0 :(得分:0)

如果你不包括

,真的很难帮助你
  • 相关build.gradle摘要
  • 实际错误

对于依赖版本不匹配,我建议您进行比较 mvn dependency:tree gradle dependencyInsight反对fetchRecordWithID,看看有什么不同。

Maven和Gradle在依赖关系层次结构中有不同的处理同一依赖关系的多个版本的方法。

  • Maven使用&#34;最接近的定义获胜&#34;战略。
  • 默认情况下,Gradle会选择最新版本(或者您也可以定义自定义ResolutionStrateegy