简体   繁体   English

为什么我的gradle构建失败,但是gradlew构建成功?

[英]why is my gradle build failing but gradlew build is successsful?

I have a gradle project that I am trying to build. 我有一个我要构建的gradle项目。

when I execute gradle clean build , it fails with the following error message 当我执行gradle clean build ,它失败并显示以下错误消息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':FacebookUpdateDependencies'.
> Could not resolve all dependencies for configuration ':compiler'.
   > Could not resolve com.company.facebook:compiler:1.2+.
     Required by:
         ::1.0
      > Could not resolve com.company.facebook:compiler:1.2+.
         > Failed to list versions for com.company.facebook:compiler.
            > Unable to load Maven meta-data from http://mycompanynexus/compiler/maven-metadata.xml.
               > Could not GET 'http://mycompanynexus/compiler/maven-metadata.xml'. Received status code 500 from server: Internal Server Error

However, when I tried ./gradlew clean build the build is successful. 但是,当我尝试./gradlew clean build ,构建成功。

why the build fails in the former and not the latter? 为什么在前者而非后者中构建失败?

here is revelant portion of build.gradle 这是build.gradle的相关部分

task wrapper(type: Wrapper) {
    gradleVersion = '2.11'
}

EDIT 编辑

local$: gradle -v

------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------

Build time:   2016-04-25 04:10:10 UTC
Build number: none
Revision:     3b427b1481e46232107303c90be7b05079b05b1c

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.7.0_79 (Oracle Corporation 24.79-b02)
OS:           Mac OS X 10.11.1 x86_64

local$ ./gradlew -v

------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------

Build time:   2014-04-29 09:24:31 UTC
Build number: none
Revision:     a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy:          2.2.0
JVM:          1.7.0_79 (Oracle Corporation 24.79-b02)
OS:           Mac OS X 10.11.1 x86_64

I just noticed that the wrapper version is 1.12 and not 2.12 . 我只是注意到包装器版本是1.12而不是2.12 That is, there is a very large version difference between the wrapper and the installed version of gradle. 也就是说,包装器和已安装的gradle版本之间存在很大的版本差异。 There have probably been many incompatible changes to the different gradle plugins over the last 2 years, which may lead to the build problems you observe. 在过去的两年中,不同的gradle插件可能进行了许多不兼容的更改,这可能会导致您观察到构建问题。

As already mentioned the gradle wrapper is a separate version of gradle that resides in the gradle/wrapper folder of your project. 如前所述,gradle包装器是gradle的单独版本,位于项目的gradle/wrapper文件夹中。 The wrapper is only built/updated, when executing the wrapper task in your project ( gradle wrapper ). 仅在项目中执行wrapper任务时( gradle wrapper ),才会构建/更新wrapper gradle wrapper That is your project's wrapper has not been updated for the last 2 years or has been created with the wrong version initially ( 1.12 instead of 2.11 ). 那是您的项目的包装器在过去两年中没有更新,或者最初使用错误的版本( 1.12而不是2.11 )创建。

Given the above it's hard the tell what is actually causing the build to fail - apart from the incompatibilities between gradle 1.12 and 2.13 . 鉴于以上所述,很难确定到底是什么导致构建失败-除了gradle 1.122.13之间的不兼容性。 But this version mismatch is probably the root cause of your problem. 但是此版本不匹配可能是导致问题的根本原因。

Most likely your project won't built anymore using the wrapper once you regenerated the wrapper with version 2.11 (the version mentioned in the build file), as 2.11 is likely to be incompatible to 1.12 as well... 一旦使用2.11版(在构建文件中提到的版本)重新生成包装器,您的项目很可能不再使用该包装器构建,因为2.11也可能与1.12不兼容...

This tells you that your Gradle version 2.11 will be used when gradlew command is invoked instead of the one installed on system. 这告诉您,调用gradlew命令时将使用Gradle 2.11版,而不是系统上安装的Gradle版本。 Always run gradlew command as it ensures your build is run against the gradle version it is supposed to, you are never required to install the correct version of gradle and really speeds up the build time. 始终运行gradlew命令,因为它可以确保您的构建可以在应该使用的gradle版本上运行,而您无需安装正确版本的gradle并可以真正加快构建时间。

Here is an excerpt from Gradle Wrapper definition: 这是Gradle Wrapper定义的摘录:

Most tools require installation on your computer before you can use them. 大多数工具都需要在计算机上安装后才能使用。 If the installation is easy, you may think that's fine. 如果安装简单,您可能会认为很好。 But it can be an unnecessary burden on the users of the build. 但这可能会对构建的用户造成不必要的负担。 Equally importantly, will the user install the right version of the tool for the build? 同样重要的是,用户是否会为构建安装正确版本的工具? What if they're building an old version of the software? 如果他们正在构建软件的旧版本怎么办?

The Gradle Wrapper (henceforth referred to as the “Wrapper”) solves both these problems and is the preferred way of starting a Gradle build. Gradle包装器(以下称为“包装器”)解决了这两个问题,是开始Gradle构建的首选方法。 If a Gradle project has set up the Wrapper (and we recommend all projects do so), you can execute the build using one of the following commands from the root of the project: 如果Gradle项目已设置包装器(我们建议所有项目都这样做),则可以从项目根目录使用以下命令之一执行构建:

./gradlew (on Unix-like platforms such as Linux and Mac OS X) gradlew (on Windows using the gradlew.bat batch file) Each Wrapper is tied to a specific version of Gradle, so when you first run one of the commands above for a given Gradle version, it will download the corresponding Gradle distribution and use it to execute the build. ./gradlew(在类似Unix的平台上,例如Linux和Mac OS X)gradlew(在Windows上使用gradlew.bat批处理文件)每个包装器都与特定版本的Gradle绑定在一起,因此,当您首次运行上述命令之一时对于给定的Gradle版本,它将下载相应的Gradle发行版并使用它执行构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM