the "build automatically" and maven in Eclipse - eclipse

in Eclipse, when Maven is enabled, there is a pom.xml file to build with Maven. And also, Eclipse has a "build automatically" option in it's project menu.
Is the "build automatically" automatically build with Maven, or we need uncheck it, because when Maven is enabled, we don't need the Eclipse build in build system anymore?

Eclipse's m2e will run the plugin goals it has lifecycle bindings for. I don't know (and I'm unable to find) what specific phases are run, but from experience I know that:
for normal operation, at least compile gets executed.
for executing tests (e.g. JUnit test cases), at least test-compile gets executed.
Note that it doesn't have all possible bindings, and going around that problem is sometimes problematic. So, usually, having both should run fine, and in fact will avoid some incongruities due to the compiled state not updating while you code.
However if you have plugins that are ignored by m2e, you should actually shut down "Build Automatically" off when you need to be certain your build completes correctly.
For example, using the Maven Properties plugin, if you have not provided a binding and set m2e to ignore, you will have resources with out-of-whack property values. The problem can especially occur when you do a "Maven" build (from the right-click context menu for example), and then do a change in your code and save it.

You need both. Here is why:
Eclipse built-in compiler is used for incremental compilation - when you save your code, for example. But full build of the project is done using maven and project configuration in pom.xml.

Related

Parallel execution of "Building" and "Load Target Platform"

I am working with a huge workspace (~1200 bundles/fragments) and a target platform (file) with about ~800 additional bundles. Settting up this workspace (switch branch, change target platform, etc.) and make it "green" takes a lot of time (20min-2hrs). During setting up this workspace I realized that some of the Eclipse internal tasks such as "Building" and "Loading Target PLatform" are executed in parallel.
But this doesn't make much sense to me, because I assume you cannot successfully build the workspace unless all required plug-in dependencies are resolved. This implies loading the target platform should be done in prior to building the actual workspace. The result is, that once "Building" and "Load TP" is finished, the workspace is a mess with >100000 errors and it requires some hardcore "Eclipse Dance"[tm] to make it "green".
My question is:
Could some sort of exclusion between those task solve this problem?
Is there a way to specify some sort of rules between those tasks from within the Eclipse IDE itself?
In case its only possible by manipulating the underlying Eclipse.org java classes, which one would that be and what would be a recommended way to do so?
The parallel building of projects can be enable in the preferences in General > Workspace > Build by setting Max simultaneous project builds to 2 or higher.
Please note that such slow building of projects as you describe is probably caused by something else:
Make sure your Eclipse (the platform and all plugins) is up to date. According to the screenshot, your Eclipse seems pretty old, so you will miss the numerous performance improvements that have been made in recent versions. For example, since EGit 5.6 only files actually modified instead of all files are refreshed when switching to a different branch.
Make sure it is not caused by a plugin you have installed. Some plugins can dramatically slow down building of projects, even when not used. So check it, whether you can reproduce it with an Eclipse without additional plugin.
Avoid circular dependencies since they can cause multiple build iteration (a project that has been changed triggers a build in the projects that depend on the project; which can result in a change that in turn can trigger the building of more projects; and so on): in Project > Properties: Java Compiler > Build set Circular dependencies to Error (which is the default).
Avoid project builder cycles. A project can have multiple builders (see Project > Properties: Builders). All builders will be executed until no file is changed. Touching a file without changing its contents is also a change. For Maven project, you can use the Maven Workspace Build view to debug this.
For large projects I disable "Build automatically" in the "Project" menu before updating from source code repository and building it with Gradle/Maven. After Gradle finished I enable "Build automatically" back.

How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

I’m using Eclipse Mars with Maven (v 3.3). When I update a dependency in my pom (change the version), my Eclipse-Maven project doesn’t pick it up, even when I right click my project, and select “Maven” -> “Update Project.” I know this because I do not see compilation errors in the Eclipse Java editor that I see when I build the project on the command line using
mvn clean install
When I remove the project from the workspace and re-import it, then things get back to normal. However this is a cumbersome process. How do I get my Maven-Eclipse project to automatically detect changes in my pom and update the project libraries appropriately?
And yes, in the “Project” menu, “Build Automatically” is checked.
When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).
So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath, .project, and folder .settings), they were generated by mvn eclipse:eclipse and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.
As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:
If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml change could end up being more trouble than it's worth.
Three Mandatory checks you should do for automatic update in your classpath
Your Repository is not in-sync with your Eclipse IDE, Please check the below settings in your IDE.
Right Click your any POM.xml from your IDE and check for the Maven profile which should be auto-activated. Also offline and Force update check box shouldn't be enabled. Please refer the below image.
Always check for your user settings which should reflect your local maven settings.xml, as shown in the below figure.
After performing all these checks, refresh your Eclipse Work-space to get these changes reflected.
Eclipse should be updating your classpath. If it's not, that implies something is going wrong.
It's hard to say what the problem could be exactly without knowing more about your project's pom.xml. More information might be necessary to solve the issue, but I'll just make a stab in the dark:
Open the .project file in your project's root folder and check the ordering of builders and natures there. It might be possible that some other nature on the project is also causing maven2Nature to fail. Move maven nature up and see if that helps any.
Alternatively you might be thinking that Eclipse does not update your dependencies because it does not add some some error indicators in the project that should be there with new dependencies. If that's the case try cleaning the current project (project>clean...). Maven in Eclipse does not necessarily trigger a full rebuild when dependencies are updated.
If none of this works, closing/opening the project might solve the issue quicker than re-importing.
What you wrote, should work. Did you check this:
does "pure" mvn install from terminal see your changes in POM?
maybe some Maybe plugin is buggy, cached some dependencies in target, and mvn clean install is needed
you can run Eclipse in a new workspace, and import your project there, sometimes it helps in case of such strange problems
instead of importing Maven project to Eclipse via m2eclipse, you can try to create Eclipse files via the old mvn eclipse:eclipse and see what happens then
does it work well when you try to import your Maven project to other IDE, the free IntelliJ Community Edition for example?
As a last resort, you can delete your current Eclipse installation and install a new version. When you add several plugins, they might interfere with one another and create weird behavior. After you do that, do not import your Maven project into your workspace, but rather create a new one and copy and paste the files that you had.

Eclipse with m2e not building tests

I have an Eclipse project that uses Maven. The regular source files (ie, in src/main) build fine in both Eclipse and Maven. However, the test files (ie, in src/test) will only build in Maven. I cannot find any way to get them to build in Eclipse.
That is, the tests in Eclipse are run as the last version which Maven compiled. Before I used Maven, tests would be compiled automatically when they were run in Eclipse. "Build automatically" in the project menu is still enabled.
This only affects the tests (which are JUnit 4 tests). As mentioned, the regular source files are being built automatically correctly.
Here's the POM file, with irrelevant data pruned: https://gist.github.com/anonymous/10001049
Add the src/test directory to your build path. Windows / Preferences / Java / Build Path, or something like that.
Updating the project might also work, since m2e can get out of sync with your pom file quite often.

m2eclipse: How do I configure parameters to the Maven Project Builder?

In Eclipse Helios with m2eclipse installed, Build Automatically is on by default. I can see that this uses some sort of incremental Maven builder under the covers (for Maven projects, obviously).
How can I customize the Maven builder so that, for example, I can supply it with some -D options? Specifically, I want my automatic, incremental Maven builds to be run with -Dmaven.buildNumber.doCheck=false. I see nowhere where I can actually affect the configuration of the m2eclipse-supplied Maven builder.
I am aware that I can create a run configuration and then explicitly build my project using Run As..., but I don't want to pursue that path. I want to customize the way my project is built when I choose the Build All command from the Project menu. I also want these customizations to be in effect when an automatic build is triggered.
I don't particularly want to add settings to my ~/.m2/settings.xml file because I don't actually want my command-line Maven installation to pick up these settings outside of Eclipse.
Thanks in advance for any help here.
At the moment, you need to put the settings in a profile and then trigger that profile. The M2E gang has removed the settings that used to be useful for this purpose.
You can make a custom settings.xml in a separate location and configure THAT in the m2e prefs.

How do I disable maven build when using Maven 2.0 integration for eclipse?

How do I stop the "Maven 2.0 integration" plugin from running maven build, while keeping "build automatically" checked?
I'm pretty sure it used to be some check box to disable maven build before, but after upgrading Ubuntu; eclipse seems to have been updated in the process, and now I cannot find any way to turn off the maven build. The maven build takes literally minutes (about 5 minutes or so), while just running java build used to finish in seconds.
Is it no longer possible to disable it or have they just hidden it well?
If it's not possible, will eclipse be able to compile my maven project without the plugin?
(Trying to google for a solution the closes I got to an answer was several archives of this old post where the answer essentially were "You should be able to disable Maven builder in project preferences..." which doesn't really help because I cannot find any on/off settings there)
To disable the Maven Project Builder, right-click on your project then Preferences > Builders and uncheck the Maven Project Builder (you cannot modify the default maven builder).
alt text http://www.imagebanana.com/img/fikqaidv/screenshot_010.png
If this removes "too much" things, you can maybe create your own custom Maven builder. Click New, select Maven Build and configure it as you want.
alt text http://www.imagebanana.com/img/rwkmm7jb/screenshot_010.png
Disabling it seems to stop eclipse from knowing about the related projects causing the java build to fail. Is there a some sort of dummy, no-operation goal I can use for auto build goals?
I guess you would have to add the related projects in the Project References (or to uncheck Resolve dependencies from Workspace projects).
Is there a way to disable it for all 6 related projects in the workspace simultaneously?
I don't think so.
At the end, all this tweaks looks like ugly hacks. If you're not satisfied by the m2eclipse plugin, maybe you should use the maven-eclipse-plugin instead (i.e. run mvn eclipse:eclipse) instead to generate the .project and .classpath files and import your projects as Existing Project into Eclipse.