IntelliJ - is there any good Maven plugin? - intellij-idea

I am trying IntelliJ 12 and one thing is really disappointing.... this is the maven integration.
I am missing following functionality:
effective pom view
search for particular jar trough dependency hierarchy
classpath should be derived directly from maven pom, and not in some crazy random unknown way. I have the case now, where some dependencies are just omitted, and I can see them when executing mvn dependency:analyze
changes is pom.xml are sometimes not reflected in project (classpath does not change, or has still old dependency and new one), also when I click "reimport"
Does anyone know some other maven plugin? Something like m2e would be really nice ;)

As #tieTYT noticed, there is a 'Dependency popup' (Ctrl+Alt+U, Ctrl+F works there).
Idea can automatically detect changes made to your pom.xml and apply them to project. To enable this, press Ctrl+Shift+A, type 'maven auto', choose "Importing", checkbox "Import Maven project automatically";

See https://stackoverflow.com/a/19582120/417846 for my answer. It at least provides a relatively easy way to get the effective pom.

I just moved from eclipse and my idea was, that there are many different plugins for single technology, well not in this case - case closed.

Related

avoid instantiating maven dependency plugin

I would like to use the "deploy"-phase of maven to deploy some files to my appliance (using a custom maven plugin), but I don't need the maven-deploy-plugin.
There are several answers on stackoverflow and the rest of the web on how to avoid a plugin being run, for example:
maven exclude plugin defined in parent pom
Disable a Maven plugin defined in a parent POM
I have tried setting <phase>none, <skip>true and <inherited>false. However, the plugin is still configured, which fails with message:
failed to configure plugin parameters for org.apache.maven.plugins maven-deploy-plugin 2.4
because there is no distributionManagement-element in my pom.
Is there a way to completely remove the dependency-plugin from the maven lifecycle?
In my opinion, this is unlikely to work even with those workarounds simply because the maven-deploy-plugin is a core plugin, like it or not.
Therefore, here's another hack:
Create a profile.
Define your plugin in it and attach it to the install phase.
Trigger the deployment, by invoking your profile.
Not as fancy as you would have hoped for, but it should do the trick. If anyone has better ideas, I would also like to hear them, as I've faced this sort of issue as well.

maven, how to find out where X:Y artifact came from?

I didn't see a clear answer from the same question
How can I figure out where Maven got an artifact from?
I have a jar slf4j-log4j that is sneaking into our project via some other artifact. In eclipse, I click on dependency hierarchy and see the jar there, I click on it and choose exclude from project which doesn't do anything....I try to right click and see if I can see it's parent that brought it into the project....nope.
How to see the graph of all parents from the artifact that was brought in?
This is all because maven doesn't seem to have global excludes like ivy does :( :( :( so I need to exclude this jar on that project that brought it in(and we have too many projects too look at each and every one).
thanks,
Dean
On the command line, do:
mvn dependency:tree -Dincludes=the.groupId
See: dependency:tree mojo
And:
I click on it and choose exclude from project which doesn't do
anything....
Are you using a current version of Eclipse with m2e? Because previous versions with m2eclipse could never do that, but m2e can.

M2Eclipse can't find dependencies when they are projects in the same workspace

I know there are various known issues with the M2eclipse plugin and I guess this is just one of them. Hopefully someone is aware of a solution or workaround.
We have like 30 projects in our workspace but for clarity lets assume there are only 2: A en B.
B includes A as a dependency in the pom.xml of B.
The problem we have is that in eclipse the classes of A can't be found so you get compilation errors. However, if you 'mvn install' A to deploy it in the local repository and the close project A then everything is fine; no compilation errors. So, if A exists in the project M2Eclipse does not seem to be able to correctly set the classpath in eclipse.
To make things stranger, we also have project C that also depends (in exactly the same way as B) on project A but here we have no compilation errors. We can't identify anything meaningful difference between project B or C; as said, they include A in the same manner.
thanks for your help,
Stijn
P.S. I'm using version 0.10.2.20100623 of the plugin
I've experienced this behavior before, and it has occurred for me in the past when I imported or checked out the maven projects separately.
Prerequisite: make sure you have m2extras installed before you check out a multi-module Maven project: update site
First thing to try: right-click each project and choose Maven -> update project configuration. The plugin might be smart enough to detect that it could be building project references between the projects.
Second thing to try (if your 30 projects are all submodules off one root): this would be easiest, because you could use the SCM integration of m2eclipse to do a "Checkout as Maven Project..." on the root pom. M2eclipse would make a project for the superpom and for each submodule, with project references built appropriately.
Third thing to try: I'd try manually creating project references in the project settings of each project to mirror their interdependencies. It'd be a lot of work, and unless you check in your eclipse .project/.settings (eww), it would have to be done individually for each working copy.
RESOLVED
finally, after agonizing hours I found the cause.
I was focussing on the .classpath and the .settings files but the problem was located in the .project file. This file in project A was missing following entry in the tag natures:
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
Adding this resolved the issues.

Maven - How to find correct groupId/artifactId to include dependency in POM

In general, what is the best strategy for finding the groupId and artifactId for a well-known dependency for use in a Maven POM? For example, how would I find the correct entry for the MySQL JDBC driver? It's not mentioned on the mysql.com site, so I would usually spend time looking for another POM that already uses the Maven repository version of the jar. This can't be the best way.
I would suggest to use http://search.maven.org
M2Eclipse, the maven integration of eclipse, supports local searchable indexes of maven repositories. So you can right-click a project or a pom.xml and do
Maven -> Add Dependency
A dialog appears where you can search for artifacts from your local indexes. Wouldn't want to miss it.
If that's not an option, use mvnrepository.com
Most of the time my IDE does this for me. But when I'm not sure I search manually; Google really helps.
You can also search on maven search engines like this mvnrepository.com.
I use http://repository.sonatype.org.
Maven site suggests to browse biblio to get maven co-ordinates; http://www.ibiblio.org/ .
Say for log4j
First, we need to know what the groupId, artifactId, and version are for log4j. We can browse ibiblio and look for it, or use Google to help by searching for "site:www.ibiblio.org maven2 log4j".
Maven metadata for log4j: http://mirrors.ibiblio.org/maven2/log4j/log4j/maven-metadata.xml
In my experience the best option is mvnrepository.com. for example in your case, just type mysql in the search text field. you will find all available artifacts that contain mysql string. in your case the one fit your needs is: mysql-connector-java
for each artifact you have a general description that helps you decide what is best for you.
once you click it you get all the available versions and once you click on a version you have all sort of information about it like the code you need to add to your pom.xml, the artifact dependencies and so on...
1. Go to http://search.maven.org
2. Search in the required jar with groupId/artifactId or Just with basic text.
Like for your case

Resolving maven dependencies

Inovking maven2 goal mvn dependency:list on an artifact pom causes to download the whole dependent artifact packages. I think only those pom files are necessary for resolving dependencies. Aren't they?
On the dependecy plugin documentation you can read that dependency:list is an alias for dependency:resolve. What you need is dependency:tree which :
Displays the dependency tree for this project.
Even with dependency:tree you will have to download dependencies.
From Arnaud Héritier (developer on Maven Project)
This is a problem in maven core which doesn't allow in 2.x to resolve dependencies without downloading artifacts.
Each mojo (plug-in in the Apache Maven) has a functionality description. See all dependency plugin functionality.
I am working with the current edition of Maven (the plug-in that shipped with Eclipse Neon), and I'm still working to get my head around how to make it do all the magical things it is claimed to be able to do.
I have the screen pictured below, in which the dependency highlighted in the left pane is unresolved.
!Dependency tree, showing missing dependency1
I thought that selecting (executing) the Update Project item off the project's context menu, as shown in the following image, would resolve it, but it left me with three errors, all, one way or another, the result of a missing dependency.
!Maven fly-out menu in project context menu2
By examining the file system, I have confirmed that the dependency is, in fact, absent.
Color me confused; why didn't that action download the missing dependency?