Gradle eclipse task doesn't add proper gradle nature

ATrubka picture ATrubka · Sep 1, 2015 · Viewed 8.5k times · Source

I have the following project structure:

  • root-gradle (build.gradle)
    • project-group1 (no build file)
      • project1 (build.gradle)
      • project2 (build.gradle)
      • ...
    • project-group2 (no build file)
      • ...

So happens that I have to recreate Eclipse projects often. I run command:

gradle cleanEclipse eclipse

After a number of runs "eclipse" task stops working as expected. Namely, it does not add gradle nature to the projects anymore and does not recognize

sourceCompatibility = 1.6

anymore attempting to build everything with 1.8 version of Java.

I added the following to the root 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.

So it looks like I have 2 problems with the gradle setup.

  1. Disappearance of the gradle nature. After a few runs Eclipse stops recognizing gradle projects. 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.

  3. Missing "G" icon for the project with restored Gradle nature.

Any help would be greatly appreciated!

Answer

Alex Q picture Alex Q · Feb 26, 2016

Using the Buildship: Eclipse Plug-ins for Gradle I had to use natures string 'org.eclipse.buildship.core.gradleprojectnature'

For Example:

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