How to add srcDir only for Eclipse buildship

In I am using the APT annotation processor from Vert.x which, unfortunately, currently generates Java source code directly into build/classes/ - so in its minecraft-storeys-maker/api/build/classes/java/main/ch/vorburger/minecraft/storeys/api there are both sources and class files: Minecraft.class, MinecraftVertxEBProxy.class,, MinecraftVertxProxyHandler.class, package-info.class

This seems to work just fine in the normal Gradle command line build - class files are present and packaged as they should be, all good.

But when running tests in Eclipse in a project set up via Buildhip, then that Vert.x generated code is obviously not found, because class files are (rightfully) in bin/. Adding this hack to build.gradle works for Eclipse:

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
            srcDir 'build/classes/java/main/'

but this, not surprisingly, then breaks the command line build as follows:

> Task :api:compileJava
Unknown file extension: api/build/classes/java/main/ch/vorburger/minecraft/storeys/api/MinecraftVertxProxyHandler.class
Unknown file extension: api/build/classes/java/main/ch/vorburger/minecraft/storeys/api/package-info.class
Unknown file extension: api/build/classes/java/main/ch/vorburger/minecraft/storeys/api/Minecraft.class
Missing header in: api/build/classes/java/main/ch/vorburger/minecraft/storeys/api/
Unknown file extension: api/build/classes/java/main/ch/vorburger/minecraft/storeys/api/MinecraftVertxEBProxy.class
Missing header in: api/build/classes/java/main/Minecraft-js/minecraft-proxy.js
Missing header in: api/build/classes/java/main/Minecraft-ts/minecraft-proxy.ts
Missing header in: api/build/classes/java/main/Minecraft-ts/minecraft-proxy.d.ts
Missing header in: api/build/classes/java/main/ch/vorburger/minecraft/storeys/api/

Long story short : How do I add a srcDir only for Eclipse Buildship, but not the regular build from command line?

PS: Assume that Vert.x won’t change overnight; although we’ll see in and if it can be improved in the future.

An eclipse { } block provides some means to make your Eclipse configuration differ from the main build definition. Have a look at EclipseClasspath and there might be some relevant examples here:

Thanks; an eclipse { } block (which works ONLY with apply plugin: 'eclipse') helped; although if I just put the sourceSets { } from above into eclipse { } then the com.github.hierynomus.license plugin would look at those sources even on the CLI (not Eclipse), which I did not want. It did do what we need like this, from the SO below:

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

Is this fine or is there a better way to do this?

Use in and