简体   繁体   中英

How to add Gradle nature for Gradle 2.0 to the Eclipse project

I have a project that can be compiled by Gradle 2 from the command prompt. But it cannot be compiled by Gradle 3.

In Eclipse I am trying to apply Configure/Add Gradle Nature. Then I am getting an error: “org.gradle.tooling.BuildException: Could not run build action using Gradle distribution ' https://services.gradle.org/distributions/gradle-3.5-bin.zip '.”

Is there any way to configure the project for Gradle 2?

Actually this BuildException is thrown when a Gradle build fails or when a model cannot be built.

Suggestion#1: Using Refresh Dependecy:

You can refresh dependencies in your cache with the command line option --refresh-dependencies .

Suggestion#2: Using deleting previous jars:

You can also delete the cached files under ~/.gradle/caches . With the next build Gradle attempts to download the dependencies again.

Suggestion#3: Using wrapper is the best solution:

If your project is previously built and deployed using specific version, then you don't need to make headache to use another version. You can easily do it by adding wrapper in build.gradle file.

// Running 'gradle wrapper' will generate gradlew - Getting gradle wrapper working and using it will save you a lot of pain.
task wrapper(type: Wrapper) {
    gradleVersion = '2.2' 
}

For more, you can go through this tutorial: The Gradle Wrapper

What the Gradle Wrapper does?

When you run the Gradle Wrapper it performs the following actions:

  1. Parse the arguments passed to gradlew
  2. Install the correct Gradle version
  3. Invoke Gradle to run the specified tasks

The wrapper is effectively completely decoupled from Gradle itself.

Wrapper configuration:

One of the files the wrapper puts in your project is a configuration file at gradle/wrapper/gradle-wrapper.properties .

This file typically looks something like this:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip

Here,

distributionBase + distributionPath --> specify the path at which the wrapper will store Gradle distributions. By default GRADLE_USER_HOME is ~/.gradle , so the wrapper will store Gradle distributions at ~/.gradle/wrapper/dists .

zipStoreBase and zipStorePath are very similar. These specify where the wrapper will store the zipped distributions it downloads.

distributionUrl --> It specifies what version of Gradle you want to use for your builds and where to download it from.

Resource Link:

Understanding the Gradle Wrapper

2 situations :

1) You are using the Gradle wrapper, set it like that :

task wrapper(type: Wrapper) { 
    // Use the proper version
    gradleVersion = '2.6'
}

2) You are not using the Grade wrapper, change the global setting in Gradle's settings page :

造船设置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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