intellij/maven (/checkstyle) - maven

Sitting in intellij community edition 11, I'd like to run checkstyle with exactly the options that maven will run it with. In fact, I'd be happy to just run a maven build of the module and get any checkstyle (or PMD (or whatever)) errors. I'm not seeing how to do this.

You can follow the steps in this documentation, create a new configuration for a maven goal and specify checkstyle:checkstyle. This can then be run from Run menu.
There could be other (better) ways, but this is based on my limited (first-time) experience with IDEA.

Related

Ant to maven conversion

I need to convert few projects from ant to maven. I know the basics of both, also read a lot of articles on how to. However, is it a good idea to write a pom using eclipse? Or is it better to write it without using eclipse? The M2Eclipse plugin needs maven to be tweaked more, will the changes related to M2Eclipse cause problems when the war is built on jenkins?
Pros of using Eclipse IDE:
The formatting of pom.xml will be taken care, when you add the 'maven-eclipse-codestyle.xml' to the code formatter, as mentioned here. Formatting will be harder when you do it without an IDE.
The auto-completion feature of eclipse will make your coding easier, since it will automatically sense the open tags and close them. You need to close all the open tags manually, if you don`t use an IDE.
You can view the dependency hierarchy of the dependencies added and hence it might be a bit helpful while managing the dependencies.This can be extremely useful ,when you have transitive dependencies (Dependencies within other dependencies). You can find more about transitive dependencies here.
An IDE will warn you of common mistakes that may occur while coding (something like, 'forgetting to close an open tag','placing a tag in an incorrect location'). This will save a whole lot of time. If you don`t use an IDE, you need to correct the mistakes only when you get an exception after executing a maven command.
Eclipse will warn of missing artifacts (when the dependencies are not present in the local repository), which can help you to fix it before executing the maven goal.
Cons of using Eclipse IDE:
m2e plugin will throw 'Plugin execution not covered by lifecycle configuration' errors all over your pom.xml files. These errors won`t affect your build, but may be quite annoying.
I personally have done migration from Ant to Maven2. IMO it is better to write pom.xml on your own so that you wont face any last minute surprises as well as you will get complete overall knowledge on what you are exactly doing with your pom file.
However if you still want to go with m2e, from my experience it did not create any problems at all. Regarding the build - I guess there shouldn't be any issue. You can refer this link if you need more info about m2e and jekins - m2e and jenkins

Maven without the mouse

I thought maven was a way to build a project without relying on your IDE. I've been following instructions that involve my IDE only to find the project only works from within the IDE.
I happen to be using intellij but I wish I didn't even have to tell you that. Am I wrong or is there a way to build a maven project using keystrokes not "click this, then that" mouse instructions that change lord knows what in the IDE. A way that will work within an IDE but not be dependent on that IDE?
I'm hoping I have been following some instructions that simply didn't have this as a goal. Is there a way to build a maven project that will work just as well in intellij as eclipse? If so how do I find it? Is there a keyword I need to know to search for?
I'm probably misunderstanding something but I hope I've made my goal of having my project only depend on maven itself clear.
You can build a maven project from its directory using -
mvn clean install
Of course this requires Maven installed on the machine you are running it from.
Please look further into the documentation here as well.

What is Workflow management using Maven?

I have only little experience using maven with eclipse. One of the job descriptions which I received has "Workflow management using Maven" as a required skill. What does this mean ? What do they possibly expect?
I think they want you to correct them? :D
I'm not sure what they refer to. I would guess it relates to the developer workflow of creating and delivering software with eclipse (?) and maven.
So setting up a project from scratch is often done from an maven archetype (a project template if you like). A lot of open source frameworks offer archetypes to start with.
For existing projects you would check out the code from version control and import it into eclipse. the m2eclipse plugin is required to do that (but I think its quite common to have it)
Then there is building the software. Which is done through executing maven phases (which will then execute plugins). See maven-phases for more details. Maven phases have default plugins that execute (for example compile will run the compiler plugin).
So your workflow would look like this: you modify the files. compile them, test them, package them, deploy the artifacts into the maven repository. the maven install phase will store the artifacts in you local repository, the maven deploy phase will upload them into the company's repository.
From there the the files are installed. Yet you can use maven plugins to install the software into a application server. That depends on the traditions of the company.
I would not think of workflow as some strict step by step think like BPMN. Development is usually done with huge amounts of personal practices (are tests written in advance or while implementing, and so on).
Hope that will help :)

maven - choose plugin phase from command line

i'm not a maven expert. in my maven2 project i have a couple of report plugins (dependency, tattletale etc). some of them are bound to 'pre-site' phase, some to 'site' phase. this way i have a nice report on my site.
but sometimes, when tests don't pass i need this report to check what's wrong. is there any way to run the same plugins (in correct order) after compile or even after dependency resolution? i just want to skip all the findubs, checkstyle etc that are run at site phase and quickly have this single report to check why my project doesn't compile or why tests fail
i'm looking for something like:
mvn -P tattletale-report compile
but any other reasonable way will do
I don't know this plugin in particular but calling goals on the jetty plugin, it works with
mvn jetty:run-exploded
to give an example. Not knowing the plugin, i'd said
mvn tattletale:report
should work. Usually the plugin documentation should give you the right goals and commands. But hacking some words in Google, it appears to be a little more complicated.

how to get over these maven/m2eclipse issues

(first, I admit, I have no love for maven/m2eclipse, but it wouldn't be that bad if I could figure out how to overcome these issues)
I am using maven/m2eclipse. m2eclipse is the only good way I know of to suck in the maven jars. Some of these may not have solutions(but I am hoping to be surprised). Maybe solving #9 solves them all?
ISSUES
When I run "mvn clean package", I am dead in the water as far as running a unit test in eclipse while maven is building as I LOVE to multitask but maven prevents me here. How to get around this?
I move eclipse to point to eclipsegen/classes but then the unit tests are still using the classes in target/classes so it's not using my latest code that I just edited in eclipse and debugging is not lining up and it's stepping on blank lines that don't have code.
If I just slightly touch the pom.xml, bam, it builds when I don't really want it to and turning of automatic builds did not seem to help.
On top of #3, I get random pom builds downloading jars which just freezes eclipse from doing anything why the jars are being downloaded(I am a bit multitasker so this frustrates me to no end)
If I want to modify or do something really custom I need, the answer is usually create a java plugin but this then would require me to create another source control project with another automated build making sure the build tags all versions so we can reproduce issues with certain versions. (in ant, I just modify the xml to do custom stuff).
(I hear there is a bug open for 5 years on this one). global exclusions because people on our project keep breaking stuff when they include new things that depend on log4j and sucking that library in breaks us so we want to globally exclude it so people stop breaking the project when adding new things (IVY has global exclusions, why doesn't maven!!!!)
The xml code for generation from an xsd in maven is about 2-3 times the code of doing it in ant. Why is this? That really shouldn't be the case I think.
Running my unit test says xxxx-12.0.8-SNAPSHOT is missing but in my pom.xml it clearly says 12.0.9-SNAPSHOT not .8. ie. m2eclipse gets into some weird state and I get screwed wasting yet more time because someone selected maven
(I don't like IvyDE for the same reasons I don't like m2eclipse). In maven, is there any way like in Ivy to say on a build MOVE ALL jars into target/lib so that I can uninstall m2eclipse(if maven had this one feature, I think all my problems might go away)....That IS AN Ivy feature that rocks by the way!!!!
NOTE: I just realized that uninstalling m2eclipse and running "mvn eclipse:clean eclipse:eclipse" is not really an option since on this project I had to import 30 projects. I think on single projects, that is a great solution.
Is there no way like ant to log the command that was run for debugging purposes? ( in maven how to log the command that was run? )
I should really look into gradle(I hear it's best of maven and ant) as the theory of maven sounded great but you can tell there was a lot of controversy over it(which usually indicates a bad tool). Good tools that really help typically do have some controversy, but not as much as maven has had so it makes me think twice as I don't want to screw the guy who takes over my project(and I know ant will work). Many people I think don't even consider that. They think "I am fine, so why won't the next guy be fine".
Any ideas on how to fix the above issues?
About #9, if you have 2 alternatives :
Execute
mvn dependency:copy-dependencies
See http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html for customization options. You'll have to set your Eclipse classpath manually to point to the newly copied jars.
Use JBoss Tools JDT Extensions to get the "Materialize Library" feature (see http://docs.jboss.org/tools/whatsnew/core/core-news-3.3.0.M4.html). You'll basically just have to right-click on the Maven Classpath library, select a destination folder, select (and rename) the jars you want, and you'll get a m2e-free project in Eclipse (still a valid Maven project in command line though).
You can install JBoss Tools JDT Extensions from http://download.jboss.org/jbosstools/updates/development/indigo/
Disclaimer: I like Maven and M2Eclipse, and I have not experienced any of the issues that you mention. In general, M2Eclipse does not get in the way much for the way I'm working.
One thing that might help is disabling the Maven Builder for the projects (right-click the project, select "Properties", then "Builders"). This will get rid of many of the issues you're complaining about.
One other thing that might help you (and comes close to #9 on your list: Uninstall M2Eclipse and use mvn eclipse:eclipse, which will generate Eclipse .project and .classpath files, which include all dependencies as Eclipse project dependencies. Whenever you add or change dependencies, you will have to run mvn eclipse:eclipse again. Give this a try...
Although it does sound like a faster PC would solve some of your issues I do agree that the m2eclipse plugin sucks (although it sucks a little less since eclipse indigo). Because of this I switched to using Intellij for a while but I switched back to eclipse after a month (for me, eclipse is still the best in spite of m2eclipse).
I use m2eclipse to be able to work in eclipse but nothing more. All my maven builds (package, install, whatever) I run with maven itself (command line) simply because there have been too many occasions where the result was different (working in one, not in the other and and maven was always correct).
So, sorry, no direct answers to your questions, just some tips:
1) do it outside eclipse
2) stick to maven standards (target/classes); that will make your life a lot easier
6) using dependency management in a parent pom might help a bit
8) if you get the same issue when running from command line then there is a problem in your pom (resolve using mvn dependency:tree), if not, see 1
9) maybe assembly is an option here but I would not recommend your approach

Resources