How to add srcDir only for Eclipse buildship


(Michael Vorburger) #1

In https://github.com/vorburger/minecraft-storeys-maker 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, MinecraftVertxEBProxy.java, MinecraftVertxProxyHandler.class, MinecraftVertxProxyHandler.java 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/MinecraftVertxProxyHandler.java
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/MinecraftVertxEBProxy.java

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 https://github.com/vert-x3/vertx-codegen/issues/181 and https://github.com/vert-x3/vertx-codegen/issues/182 if it can be improved in the future.


(Luke U) #2

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:


(Michael Vorburger) #3

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 https://github.com/pmlopes/vertx-starter/pull/16/files and https://github.com/vorburger/minecraft-storeys-maker/commit/f8b1d25494a91042b618ca12032304c988af1b76.