Configure eclipse to perform different tasks on save - eclipse

I migrated my projects to use the Gradle builds for all actions (building, testing, etc). When I save in eclipse, it builds with the default eclipse actions. Is there a way to change eclipse's behavior so that when I hit the save button or Ctrl-S it will run gradle build?

In the Project Properties on the Builders page you can control which builders are run when the project changes. You can disable existing builder and add new one using either Ant or running a program.

Related

Configure Eclipse project to run "mvn generate-sources" when building automatically

I have a Maven project in Eclipse that's running some commands to generate a couple files (these files are placed on the Classpath of another Java project). When the "Build Automatically" option is checked, instead of running the typical builders, I would like it to run "mvn generate-sources", add that folder to the project Classpath, and refresh the directory so the new generated files are available to the other project.
I tried adding a custom builder that runs a dummy program and refreshes the directory containing the generated files, but when Eclipse detects that those generated files have been changed, it triggers another rebuild, which causes Eclipse to go into this infinite loop of rebuilding this project. How can this project be set up to automatically regenerate these files without sending Eclipse into this infinite loop? Does a custom plugin need to be created?
The other Builders in the project were causing the infinite loop. Right clicking the project -> Properties -> Builders -> Deselect all the other builders in the project except the custom one.
After doing this, the project properly rebuilds itself automatically without going into an infinite loop, and the other projects pick up the changes automatically.

How to automatically update Targets for an Ant build via Eclipse with new run configurations

We are creating some JUnit tests as part of QA development. So we are doing this daily and while running individual tests, or part of a package, they do appear under the Run arrow:
they do not appear in the Ant build Targets:
Well.. you can see that the Schedules_Load appears but that's because I have exported the Ant build again.
Note that even if I create Run configurations using the Eclipse menu:
It still doesn't update my Ant Targets list..
Under the menu item Project I do have Build automatically checked but don't think it makes any difference anyway, just thought I would mention it.
So is there any way to automatically update Ant targets with new run configurations without having to export the Ant build again?
Thanks.
try selecting the check-box: "Refresh automatically".
Window->Preferences->General->Workspace->"Refresh automatically"
(source: avajava.com)

Refreshing eclipse-project at the end of a maven build

Is there a possibility to refresh the files and folders of a project within eclipse at the end of a maven build automatically.
Usually I'm building from commandline. After a build e. g. the target folder should be refreshed.
Additional info: the maven build runs in the command line and eclipse should update automatically when it ended.
Use Run as -> Maven build... In the run configuration/build properties go to the refresh tab and select the refresh option you want.
Note that the eclipse build and the maven build may interfere, so make sure that you turn off the Build automatically option in the Project menu before staring the maven build. You may get indeterministic compilation errors otherwise.
Here is an eclipse plugin that implements the external hook for refreshing: https://github.com/andrask/maven-eclipse-control-plugin
I dont think so, there is no option to link the two things.
But eclipse has an option Refresh on access which might be useful for you.
For me, the accepted answer of using Run as -> Maven build... and the Refresh option did not refresh the target folder in Eclipse. I needed to do the following:
Preferences -> General -> Workspace -> Refresh using native hooks or polling
When enabled, any changes made by external editors will be automatically discovered by the Workbench. On some systems there may be a slight delay if polling is used.

automatically disable "build automatically" in eclipse during ant run

Is there a way to automatically disable the "build automatically" setting in eclipse while an ant build is running?
It should listen for an ant task being started
check if the setting is enabled
disable it temporarily
listen for the ant build to finish
restore the previous setting
I would like to have this, because having this enabled makes my ant build take ~10 minutes and having this setting disabled lets it finish in ~5 minutes. I often forget to always change the setting and so I waste lots of time waiting. Having this automated would improve my build-cycles.
If there is nothing out there yet, I would be willing to write a plugin for this. In that case does anyone have pointers about how to listen for the events and change the setting? :)
EDIT:
I want to fix this for manually started ant builds via right clicking the build.xml and clicking run as -> ant build. I do not use ant builders in my eclipse project configuration.
I suggest that you narrow down what resources you actually want to refresh in the Ant Builder's Refresh tab
and/or move Ant Builder behind Java builder in the Builders configuration.

Eclipse adding your own build command

I am new to eclipse and wanted to do the following:
Use my custom build commands with eclipse. Until now I only saw make all. I use a shell script for building my project; how can I use that in an Eclipse environment?
When I create a new project with the existing source code, it doesn't add the files, without building the code and if code fails to build (because I generally don't have make all).
How do I resolve this issue?
You can add a custom builder in the "Builders" category of the project properties.
project->properties->builders->new
there you can also deactivate the default eclipse builders..
hope that helped
In addition to what smeg4brains said and assuming that you are using the CDT plugin you can go to:
project -> properties -> C/C++ Build
Uncheck Use default build command on the Builder Settings tab and replace make with e.g. scons.
On the Behaviour tab you can then specify the target to call for the Build and Clean phase.
To resolve your second issue open the Project menu and uncheck Build automatically.
This will prevent Eclipse from building the project when it thinks it is necessary.
If you want to add other your own commands then the easiest way is to write Ant file for your project so by clicking once you can execute all your commands.To see how to write Ant file click here
I was able to do something similar to have protoc run on my .proto files. I did it by adding a "Make Target" to the project.
A lot of stuff in Eclipse you can get around using Ant, which are XML scripts, and there is also a ANT project builder which uses those. If you don't like to mess with frankly quite touchy GUI options, just write a build.xml and use ANT build as the project builder.