How to combine mvn clean and mvn install into a single task? - eclipse

I'm following the Scala, Eclipse and Maven Integration tutorial.
It is really useful.
But there is one thing that seems annoying to me:
I always need to run two commands from the Eclipse Run as menu:
Maven clean
Maven install
Is there any way to configure Scala and Maven plugins for Eclipse, to make it possible to run both tasks as a single command from the Eclipse menu?
For example:
Maven clean install
like in the following Eclipse non-Scala configuration.

Choose the option Maven build..., and type clean install in the Goals text box.

Related

Where maven is installed (eclipse plugin)

I have M2Eclipse plugin installed on my eclipse, and now I am reading a book that says to use the mvn command, I think that I could use eclipse IDE to follow the book, but I want to know a little more about maven. Of course, the command "mvn" is not recognized, I need to edit my PATH variable.
I googled where is maven installed, and the answer is that it is an apache tool and the path is where you want to unzip the package.
BUT, what if I donĀ“t want to install the apache project?? Is there any other option, because how I say at the beginning, I have M2Eclipse plugin installed, so I image that the executable file must to be in some folder into the plugin eclipse path... or does it use only java jar libraries without a binary??
Thank you very much.
M2E is a plugin in Eclipse and not Maven. You are using an embedded Maven version which is part of Ecilpse. You should always install Maven to be useable via command line cause there are difference between M2E/Eclipse and command line.
You can run any mvn goal by clicking on a maven project, than right click and select Run As -> Maven Build... and type any goal you want.

Why Eclipse clean after mvn clean install

I have a interesting observation at my new job at a Major Silicon Valley Company.
This is a mvn/java project.
I am being told to do command-line "mvn clean install" and then go to Eclipse and select Project & then do "Clean" Build.
I am confused as the difference between "mvn clean install" & Eclipse "Clean", I thought since it's the same pom.xml the outcome should be the same. Interstingly my code changes to java classes do not show till I have done both. I was expecting to see changes after command-line "mvn clean install"
Eclipse has own project structure and build routines.
Maven has own project lifecycle.
Maven integrates into Eclipse with m2e plugin. It is some kind of art to relate Maven and Eclipse stages one to one.
Therefore it very easy to fall into situation when some Eclipse command did not doing all what Maven needs and vice versa, just because m2e can not relate all features of Eclipse and Maven 1 to 1.
Simplest advice is to use Eclipse IDE support for code navigation and editing, but use Maven to clean, compile, package and so on. In this case Eclipse's 'Runtime configurations' very helpfull in configuring and executing Maven's commands.
Use 'Alt+F5' to sync project state.

is it necessary to install testng plugin when testng dependency is added in maven project

I have selenium maven project in which the dependency for the testng is added. But i'm not able to see the run as TestNG in the "run" options. should i install testng plugin for eclipse
For eclipse, the plugin is required if you want to run as TestNG. The only other alternative to run tests from eclipse would be, if you have the maven plugin installed, then you can still trigger your tests by running as mvn test, but testng plugin would definitely simplify stuff.
If you are running from maven either from command line or from Jenkins, then plugin is not required.
If you are using Intellij Idea as IDE, then it will be available by default so don't need to even have it as dependency in maven but in case of eclipse you have to explicitly install it.

Maven plugin with eclipse

I am trying to assemble Maven plugin with eclipse. For that I have already installed the m2eclipse. Now, in the new project, I have created a new Maven project.
When I try to run it by right clicking to the application, there are several options available.
When I run as Maven build, it gives build faliure but if I run as any other option such as maven install or maven clean or maven test, it gives build success.
Why so ?
On right click, when you do maven build, enter the command clean install and then try.

maven adds dependency but eclipse does not see it

I've created a new project in maven like this:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
After that I use: mvn eclipse:eclipse
The problem is that when I add the project to my IDE, eclipse indicates errors. When I run it I get classNotFound for JUnit. In project properties I see that junit is added to build path
In project properties I see: M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar
But I cant use for example: import junit.framework.Test;
Why is that? To be honest, I have some major problems with dependency in maven and eclipse. Maven adds them correctly but eclipse doesn't see it correctly. It's not only the junit. What should I check/set?
Should I install some plugin to eclipse for maven support ?
EDIT
I thought again about everything. Of course the problem was small. M2_REPO was not recognize by Eclipse. I've added this variable and set it in od maven directory. It worked like a charm.
You can use the m2eclipse plugin for eclipse
http://m2eclipse.sonatype.org/installing-m2eclipse.html
I don't know if having the plugin would solve your problem, I used to do the command line before I started using m2elcipse, I never had the issue that you described
what version of eclipse are you using?