ATrubka
ATrubka

Reputation: 4004

Gradle eclipse task doesn't add proper gradle nature

I have the following project structure:

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.

Upvotes: 12

Views: 12157

Answers (6)

user17297321
user17297321

Reputation: 1

Remove Gradle Nature close ecllips then go to project folder structure and run the command "./gradlew clean build -x test cleanEclipse eclipse" next open eclipse and just refresh the project

Upvotes: 0

user1973596
user1973596

Reputation: 51

I think you must set gradle to your system environment. Steps:

  1. Install Gradle from gradle website.
  2. Go to eclipse preferences set Home path in gradle EnIDE like C:\gradle-2.3 or whatever directory you have installed.
  3. Also make sure to add path to your system environment variable.

Upvotes: 2

Mahfuz Ahmed
Mahfuz Ahmed

Reputation: 731

Screenshot of the root dir

in the settings.gradle >>

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

here NIDVSADesktop is my root project. in the root project gradle

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

}

here Secugen and Morpho are my 2 sub projects

Upvotes: 0

Alex Q
Alex Q

Reputation: 3260

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'
    }
}

Upvotes: 9

RaGe
RaGe

Reputation: 23805

If there is an evaluation phase race condition, you can eliminate it by using the afterEvaluate qualifier. I would try:

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

Upvotes: 3

Verhagen
Verhagen

Reputation: 4044

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.

Upvotes: 4

Related Questions