如何使用 Buildship 在 Eclipse 中更改 Gradle 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32032010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:47:57  来源:igfitidea点击:

How to change Gradle version in Eclipse using Buildship?

eclipsegradlebuildship

提问by Evandro Pomatti

I am running Eclipse Luna SR2 with Buildship 1.0.1.

我正在使用 Buildship 1.0.1 运行 Eclipse Luna SR2。

The Gradle projects I create using the wizard are building with Gradle 2.5-rc-2, but I would like to use 2.6 which is the latest version.

我使用向导创建的 Gradle 项目是使用 Gradle 2.5-rc-2 构建的,但我想使用最新版本的 2.6。

How can I do it?

我该怎么做?

Setting the task had no effect:

设置任务没有效果:

apply plugin: 'java'

repositories {
    jcenter()
}

dependencies {
    testCompile 'junit:junit:4.12'
}

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

Solution: For some reason it is only working if I restart Eclipse after setting the version as Makoto suggested.

解决方案:出于某种原因,只有在按照 Makoto 建议设置版本后重新启动 Eclipse 时它才有效。

采纳答案by Makoto

If you want to use the wrapper, it's a simple matter of setting the gradleVersionproperty:

如果要使用包装器,只需设置gradleVersion属性即可:

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

回答by jpmath

You can create a new Run Configurationof type Gradle Projectrunning the task wrapper. Running this run configuration should update the wrapper version without the need to restart eclipse.

您可以创建一个运行任务的新Run Configuration类型。运行此运行配置应该会更新包装器版本,而无需重新启动 eclipse。Gradle Projectwrapper

回答by SteadyBigman

I had the same issue with different versions. The solution is to add the following task to your build file, then run gradle wrapper task in the project root folder:

我在不同版本中遇到了同样的问题。解决方案是将以下任务添加到您的构建文件中,然后在项目根文件夹中运行 gradle wrapper 任务:

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

The reason the wrong version of wrapper was used for the build is that there was no wrapper created for the version I wanted to use.

错误版本的包装器用于构建的原因是没有为我想要使用的版本创建包装器。