Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null Pointer Importing Gradle Project Into Eclipse

I used libGDX to generate some gradle projects that I now need to import into Eclipse. So, I opened Eclipse, installed the gradle plugin, and went to File -> Import -> Gradle Project. At that point, I chose the directory that contained my generated gradle projects. Then, I clicked 'Build Model' and then added my projects to the list of available projects to import. After I select 'Finish' Eclipse begins importing them. Right at the very end I get this dialog:

enter image description here

Looking in the log file, I found this stack trace:

java.lang.NullPointerException
at org.springsource.ide.eclipse.gradle.core.wizards.GradleImportOperation.refreshProjects(GradleImportOperation.java:256)
at org.springsource.ide.eclipse.gradle.core.wizards.GradleImportOperation.perform(GradleImportOperation.java:195)
at org.springsource.ide.eclipse.gradle.ui.wizards.GradleImportWizard$1.doit(GradleImportWizard.java:66)
at org.springsource.ide.eclipse.gradle.core.util.GradleRunnable$1.run(GradleRunnable.java:49)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

I've tried reinstalling everything relevant. I've created the projects several times. I've downloaded a fresh version of eclipse. But, the same issue occurs everytime. Any help would be great. Thank you.

like image 466
Troncoso Avatar asked Apr 14 '14 01:04

Troncoso


People also ask

Can we use Gradle in Eclipse?

In the eclipse, go to file -> click on new-> click on other projects. Now, you will see the following screen. Later on, select Gradle project and click next.


2 Answers

In case it helps someone else in the future, I had the same problem, but a different resolution. My issue was resolved when I moved the projects out of the eclipse workspace directory. It can be in another directory entirely, or in a subdirectory.

BROKEN:

/path/to/workspace/.metadata
/path/to/workspace/build.gradle
/path/to/workspace/core
/path/to/workspace/etc

WORKS:

/path/to/workspace/.metadata
/path/to/workspace/projects/build.gradle
/path/to/workspace/projects/core
/path/to/workspace/projects/etc

I did not need to remove the "afterEclipseImport" script. See this issue: https://github.com/libgdx/libgdx/issues/1537#issuecomment-38535167

like image 127
Steve Blackwell Avatar answered Nov 06 '22 22:11

Steve Blackwell


As it turns out, when importing a gradle project, there is a field called "Run After" which defaults to "afterEclipseImport". This doesn't exist unless it is defined in the project you are importing. The documentation says that if it doesn't exist then the gradle import project skips over it. Well, once I unchecked this option, the import worked correctly.

Edit: Just as an aside. This assumes that your project is in a subdirectory inside your workspace as opposed to the workspace directory itself. (See the other answer).

like image 29
Troncoso Avatar answered Nov 06 '22 20:11

Troncoso