Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add gradle generated source folder to Eclipse project?

My gradle project generates some java code inside gen/main/java using annotation processor. When I import this project into Eclipse, Eclipse will not automatically add gen/main/java as source folder to buildpath. I can do it manually. But is there a way to automate this?

Thanks.

like image 445
codefx Avatar asked Nov 05 '14 06:11

codefx


1 Answers

You can easily add the generated folder manually to the classpath by

eclipse {
    classpath {
        file.whenMerged { cp ->
            cp.entries.add( new org.gradle.plugins.ide.eclipse.model.SourceFolder('gen/main/java', null) )
        }
    }
}

whereby null as a second constructor arg means that Eclipse should put the compiled "class" files within the default output folder. If you want to change this, just provide a String instead, e.g. 'bin-gen'.

like image 52
Andreas Schmid Avatar answered Oct 05 '22 23:10

Andreas Schmid