Sunday, November 29, 2009

Maven plugin groupId org.codehaus.mojo not searched by default??

I got interested in removing all my explicit org.codehaus.mojo declarations on my plugin dependencies since now Maven supports searching that groupId for a plugin's artifactId. This feature was added a while ago I guess.

Just came across a nasty little bug in Maven 2.2.1 which has been reported since 2.0.9.

[#MNG-4001] Unable to resolve Dashboard mojo from Central -

The summary above is very misleading. In fact I consider myself lucky to find it since it more has to do with any org.codehaus.mojo based plugin.

When I did try to remove my plugin's groupIds I got the classic "Unable to find resource 'org.apache.maven.plugins:buildnumber-maven-plugin:pom:1.0-beta-4' in repository central".

Turns out this may be related to maven metadata in my local repo and/or the remote repos being randomly deleting version info???? See the bug followups for more info.

In fact this bug is nasty because
1. there is no mention in the error that is what could be wrong.
2. Adding a pluginGroups section to your ~/.m2/settings.xml file with that group changes nothing, even in the error output. Plus using -X shows that maven does not even try to locate org.codehaus.mojo version of that plugin or any other groupId specified in your pluginGroups settings. It may have looked at the metadata, but we would never know.
3. Deleting your local maven metadata may only fix the error temporarily or not at all.
4. Try this: Define your plugin configuration in pluginManagement without the groupId. Next, define the same plugin in a profile with the groupId. Run a mvn cmd that activates the profile and you will notice that none of your plugin settings inside plguinManagement gets picked up - and of course there is no warning or messages in the debug output that complain. Add the group id to the pluginManagement section and it all of a sudden works as expected.

So the rule of thumb is leave well enough alone and always explicitly specify the groupId for all plugins except org.apache.maven.plugins groupId which still work.

No comments:

Post a Comment