Dependencies for generated classes in Eclipse

I’m working on a multi-project set-up. One of the sub-projects generates some code during its build procedure (based on some XSD-files). The output is a bunch of class files placed in the sub-project build/classes directory.

Everything seems to work fine, except when importing to Eclipse!

Some java files in the main project depends on the generated files, and for some reason, Eclipse cannot see the generated files.

There appears to be a somewhat silly work-around for this situation:

I build the project, the Gradle script works fine. Everything builds, but Eclipse is still unhappy.

I delete the projects in the Eclipse Workspace and import the files again (the files are physically placed outside the Workspace directory), Eclipse is happy again, and shows the project without errors.

After deleting and re-importing the project, things appears to be working. I can then clean the projects, and Eclipse will of course show that some files are missing. Building the project again and everything works.

My question is therefore: Is there a better way to get around this? Something tells me that the Eclipse plug-in for Gradle has not set-up Eclipse correctly in the first place, and something gets corrected after the import.

I think the problem here is caused by the fact that Eclipse will usually ignore compiled classes in build/classes directory and instead will build sources into its bin directory (remapping it to build also into build/classes causes various troubles). I’d recommend to generate them into something like build/generatedClasses and add this folder to outputs of sourceSet.main. Cf.