简体   繁体   English

Gradle eclipse 任务没有添加适当的 gradle 性质

[英]Gradle eclipse task doesn't add proper gradle nature

I have the following project structure:我有以下项目结构:

  • root-gradle ( build.gradle )根梯度( build.gradle
    • project-group1 (no build file) project-group1(无构建文件)
      • project1 ( build.gradle )项目 1 ( build.gradle )
      • project2 ( build.gradle )项目 2 ( build.gradle )
      • ... ...
    • project-group2 (no build file) project-group2(无构建文件)
      • ... ...

So happens that I have to recreate Eclipse projects often.碰巧我不得不经常重新创建 Eclipse 项目。 I run command:我运行命令:

gradle cleanEclipse eclipse

After a number of runs "eclipse" task stops working as expected.多次运行后,“eclipse”任务停止按预期工作。 Namely, it does not add gradle nature to the projects anymore and does not recognize也就是说,它不再向项目添加 gradle 性质并且不识别

sourceCompatibility = 1.6

anymore attempting to build everything with 1.8 version of Java.不再尝试使用 1.8 版 Java 构建所有内容。

I added the following to the root build.gradle :我在根build.gradle添加了以下build.gradle

allprojects {
    sourceCompatibility = 1.6
    eclipse.project {
        natures 'org.springsource.ide.eclipse.gradle.core.nature'
    }
    // more stuff here ...
}

This helped with the root project, but had no effect on any other project.这有助于根项目,但对任何其他项目没有影响。 I added the same thing to subprojects with the same unsatisfactory result.我在子项目中添加了同样的东西,结果同样不令人满意。 I have to say than even after the nature had been added to the root project and Gradle plugin options became available for the root again I still don't see the "G" icon.我不得不说,即使在将自然添加到根项目并且 Gradle 插件选项再次可用于根之后,我仍然没有看到“G”图标。

So it looks like I have 2 problems with the gradle setup.所以看起来我的 gradle 设置有两个问题。

  1. Disappearance of the gradle nature. gradle 性质的消失。 After a few runs Eclipse stops recognizing gradle projects.运行几次后,Eclipse 停止识别 gradle 项目。 I wouldn't even face the second problem if that worked properly.如果工作正常,我什至不会面临第二个问题。

  2. Some problem with my gradle build files or projects layout as my settings don't seem to take effect on subprojects.我的 gradle 构建文件或项目布局存在一些问题,因为我的设置似乎对子项目无效。

  3. Missing "G" icon for the project with restored Gradle nature.具有恢复的 Gradle 性质的项目缺少“G”图标。

Using the Buildship: Eclipse Plug-ins for Gradle I had to use natures string 'org.eclipse.buildship.core.gradleprojectnature' 使用Buildship:Gradle的Eclipse插件我不得不使用自然字符串'org.eclipse.buildship.core.gradleprojectnature'

For Example: 例如:

allprojects {
    eclipse.project {
        natures 'org.eclipse.buildship.core.gradleprojectnature'
    }
}

Install Gradle plug-in for Eclipse 安装Eclipse的Gradle插件

Then use Eclipse menu: File -> Import... to import the Gradle project. 然后使用Eclipse菜单: File - > Import ...导入Gradle项目。 It will add the Gradle Nature. 它将添加Gradle Nature。 And 2 extra Eclipse views, one for quickly running Gradle tasks. 还有2个额外的Eclipse视图,一个用于快速运行Gradle任务。 One for Gradle output of those executed tasks. 一个用于Gradle输出执行的任务。

TIP: Before importing an existing Gradle project, create a New Gradle project, to see if the Gradle plug-in is working as expected. 提示:在导入现有Gradle项目之前,请创建一个New Gradle项目,以查看Gradle插件是否按预期工作。

New Gradle Project 新Gradle项目

  • Use the Eclispe menu: File -> New -> Other... 使用Eclispe菜单: 文件 - >新建 - >其他...
  • Select the wizard: Gradle -> Gradle Project 选择向导: Gradle - > Gradle Project
  • Enter the project name 输入项目名称
  • Press the button Finish 按“ 完成 ”按钮

This should set up a minimal Gradle project. 这应该设置一个最小的Gradle项目。

If there is an evaluation phase race condition, you can eliminate it by using the afterEvaluate qualifier. 如果存在评估阶段竞争条件,则可以使用afterEvaluate限定符将其消除。 I would try: 我会尝试:

allprojects {
    afterEvaluate {
        eclipse.project {
            natures 'org.springsource.ide.eclipse.gradle.core.nature'
        }
    }
}

I think you must set gradle to your system environment. 我认为你必须为你的系统环境设置gradle。 Steps - 脚步 -

  • Install Gradle from gradle website. 从gradle网站安装Gradle。
  • Go to eclipse preferences set Home path in gradle EnIDE like "C:\\gradle-2.3" 转到eclipse首选项设置gradle中的主路径EnIDE如“C:\\ gradle-2.3”
    or whatever directory you have installed. 或者您安装的任何目录。
  • Also make sure to add path to your system environment variable. 还要确保添加系统环境变量的路径。

在此输入图像描述

in the settings gradle >> 在设置gradle中>>

 include 'Device', 'Secugen', 'Morpho', 'NIDVSADesktop'

here NIDVSADesktop is my root project. 这里NIDVSADesktop是我的根项目。 in the root project gradle 在根项目gradle中

dependencies {
  compile project(':Secugen') 
  compile project(':Morpho')

}

here Secugen and Morpho is my 2 sub projects Secugen和Morpho是我的2个子项目

删除 Gradle Nature close eclips 然后转到项目文件夹结构并运行命令“./gradlew clean build -x test cleanEclipse eclipse”然后打开 eclipse 并刷新项目

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

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