Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle eclipse task doesn't add proper gradle nature

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.

like image 932
ATrubka Avatar asked Sep 01 '15 21:09

ATrubka


2 Answers

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'
    }
}
like image 197
Alex Q Avatar answered Sep 21 '22 17:09

Alex Q


Install Gradle plug-in for Eclipse

Then use Eclipse menu: File -> Import... to import the Gradle project. It will add the Gradle Nature. And 2 extra Eclipse views, one for quickly running Gradle tasks. One for Gradle output of those executed tasks.

TIP: Before importing an existing Gradle project, create a New Gradle project, to see if the Gradle plug-in is working as expected.

New Gradle Project

  • Use the Eclispe menu: File -> New -> Other...
  • Select the wizard: Gradle -> Gradle Project
  • Enter the project name
  • Press the button Finish

This should set up a minimal Gradle project.

like image 20
Verhagen Avatar answered Sep 21 '22 17:09

Verhagen