How to change the default Eclipse Java Builder with Gradle

(Martin) #1


another questoin for you: I am using STS 2.7.2 with Gradle Tool installed.

Normally I was using commandline all the time, since I got the idea, to use the gradle compile task for compilation of my classes. The thing is: I have 1800 classes to compile, with x template htmls and x other resources. It takes so much time, if I have set Menubar -> Project -> Build Automatically, because it builds via eclipse first. Then I still need to run gradle compile and gradle test to verify, my code works.

I want to have gradle compiling the resources once, not eclipse first + gradle later. And I would like to run my unit-tests via gradle if possible. Is there a way to exchange the Java Builder of eclipse? How can I specify the Unit-Test execution? Is there a way to run the gradle build within eclipse with the wrapper batch?

FYI: you can (change) see the Java Builder of your Project in Eclipse if you right-click on your Project folder -> Properties -> Builders. I want to get a Gradle compiler inside there, instead of the Java Builder.

Sorry for that many questions in one post.

Thanks in advance for everyone answering.

EDIT: I have seen there is another question pretty much the same as this one. So let me add this: Now Eclipse builds the classes to the default location /bin. Gradle builds the classes to the default location /build/classes

Do I need to redirect the output folder for eclipse to the /build/classes to have it just once building?

(Peter Niederwieser) #2

There isn’t currently a Gradle builder for Eclipse. As of today, the only IDE that delegates the IDE build to Gradle is Netbeans. As an Eclipse user, the best option is to set up Eclipse so that you can spend the majority of the time in the IDE (compile, debug, test, etc.). If you additionally need Gradle to generate some resources, you can call that task occasionally (after a related change) and configure Eclipse to pick up its outputs. Or you can execute the task directly from Eclipse (via a tool configuration).

I don’t think that using the same output folder for Gradle and Eclipse will speed up the build, as both tools maintain their own information about the state of the build. (You can, however, give it a try.) From my experience, using the same output folder can cause strange problems, which isn’t too surprising when you think about it (two different compilers partially overriding each others’ files without any coordination).