Thursday 31 May 2007

Maven woes #98797894 - WTF is going on? Why the hell do I continue to get these plugin resolution errors? (Problems AND Solutions)

What the hell is this "just supposed to work" idea I've somehow got into
my head? Did I accidentally drink the Kool-Aid in the 3 years we had
one of the Maven developers in our team? The dependency management
aspect is cool and all, but plugin resolution sucks so badly.

I'm trying to run the Spring-WS samples, and I can't even get past STEP
2! For chrissake, I'm already doing this from home, not going through a
proxy, directly connected via Ethernet to my router, and it is still
getting these goddamn problems getting its plugins!


$ mvn -P hsqldb sql:execute
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'sql'.
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: org.codehaus.mojo:sql-maven-plugin

Reason: Error getting POM for 'org.codehaus.mojo:sql-maven-plugin' from
the repo
sitory: Failed to resolve artifact, possibly due to a repository list
that is no
t appropriately equipped for this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu May 31 04:16:24 EST 2007
[INFO] Final Memory: 1M/2M
[INFO]
------------------------------------------------------------------------

me@homer /spring-ws/samples/airline/hsqldb

$ mvn -P hsqldb sql:execute -U -e
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'sql'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] artifact org.codehaus.mojo:sql-maven-plugin: checking for updates
from ce
ntral
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: org.codehaus.mojo:sql-maven-plugin

Reason: Error getting POM for 'org.codehaus.mojo:sql-maven-plugin' from
the repo
sitory: Failed to resolve artifact, possibly due to a repository list
that is no
t appropriately equipped for this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

[INFO]
------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error resolving
version
for 'org.codehaus.mojo:sql-maven-plugin': Unable to read the metadata
file for a
rtifact 'org.codehaus.mojo:sql-maven-plugin:pom': Error getting POM for
'org.cod
ehaus.mojo:sql-maven-plugin' from the repository: Failed to resolve
artifact, po
ssibly due to a repository list that is not appropriately equipped for
this arti
fact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(Defa
ultLifecycleExecutor.java:1266)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor
(DefaultLifecycleExecutor.java:1522)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListBy
AggregationNeeds(DefaultLifecycleExecutor.java:386)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:138)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:272)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at
org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by:
org.apache.maven.plugin.version.PluginVersionResolutionException: Err
or resolving version for 'org.codehaus.mojo:sql-maven-plugin': Unable to
read th
e metadata file for artifact 'org.codehaus.mojo:sql-maven-plugin:pom':
Error get
ting POM for 'org.codehaus.mojo:sql-maven-plugin' from the repository:
Failed to
resolve artifact, possibly due to a repository list that is not
appropriately e
quipped for this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

at
org.apache.maven.plugin.version.DefaultPluginVersionManager.resolveMe
taVersion(DefaultPluginVersionManager.java:681)
at
org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePl
uginVersion(DefaultPluginVersionManager.java:186)
at
org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePl
uginVersion(DefaultPluginVersionManager.java:90)
at
org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPlug
inManager.java:166)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(Defa
ultLifecycleExecutor.java:1257)
... 14 more
Caused by:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
: Unable to read the metadata file for artifact
'org.codehaus.mojo:sql-maven-plu
gin:pom': Error getting POM for 'org.codehaus.mojo:sql-maven-plugin'
from the re
pository: Failed to resolve artifact, possibly due to a repository list
that is
not appropriately equipped for this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

at
org.apache.maven.project.artifact.MavenMetadataSource.retrieve(MavenM
etadataSource.java:134)
at
org.apache.maven.plugin.version.DefaultPluginVersionManager.resolveMe
taVersion(DefaultPluginVersionManager.java:672)
... 18 more
Caused by: org.apache.maven.project.ProjectBuildingException: Error
getting POM
for 'org.codehaus.mojo:sql-maven-plugin' from the repository: Failed to
resolve
artifact, possibly due to a repository list that is not appropriately
equipped f
or this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

at
org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepo
sitory(DefaultMavenProjectBuilder.java:560)
at
org.apache.maven.project.DefaultMavenProjectBuilder.buildFromReposito
ry(DefaultMavenProjectBuilder.java:234)
at
org.apache.maven.project.artifact.MavenMetadataSource.retrieve(MavenM
etadataSource.java:105)
... 19 more
Caused by:
org.apache.maven.artifact.resolver.ArtifactResolutionException: Faile
d to resolve artifact, possibly due to a repository list that is not
appropriate
ly equipped for this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

at
org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(De
faultArtifactResolver.java:190)
at
org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(De
faultArtifactResolver.java:73)
at
org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepo
sitory(DefaultMavenProjectBuilder.java:526)
... 21 more
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu May 31 04:39:40 EST 2007
[INFO] Final Memory: 1M/2M
[INFO]
------------------------------------------------------------------------


Okay, so the main error is this:

Caused by: org.apache.maven.project.ProjectBuildingException: Error
getting POM
for 'org.codehaus.mojo:sql-maven-plugin' from the repository: Failed to
resolve
artifact, possibly due to a repository list that is not appropriately
equipped f
or this artifact's metadata.
org.codehaus.mojo:sql-maven-plugin:pom:1.1-SNAPSHOT


Does anyone actually check this metadata before dumping it in the
fucking maven repository?


In the .m2\repository\org\codehaus\mojo\sql-maven-plugin directory on my
PC, I have a file maven-metadata.xml which contains:


<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.0-beta-1-SNAPSHOT</version>
<versioning>
<latest>1.1-SNAPSHOT</latest>
<versions>
<version>1.0-beta-1-SNAPSHOT</version>
<version>1.0-beta-2-SNAPSHOT</version>
<version>1.0-beta-2-20060821.223722-1</version>
<version>1.0-beta-2-20060821.234648-2</version>
<version>1.0-beta-2-20060822.021210-3</version>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</versions>
<lastUpdated>20070221045741</lastUpdated>
</versioning>
</metadata>


However, if I go to the URL:

http://repo1.maven.org/maven2/org/codehaus/mojo/sql-maven-plugin/maven-metadata.xml

The file contains this:

<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<versioning>
<latest>1.0</latest>
<release>1.0</release>

<versions>
<version>1.0-beta-1</version>
<version>1.0-beta-2</version>
<version>1.0</version>
</versions>
<lastUpdated>20070125135425</lastUpdated>
</versioning>

</metadata>


So where in heaven's name did Maven get the metadata file that got
downloaded to my computer?

=======================

Okay, looks like I found the problem:


<mirrors>
<mirror>
<id>codehaus snapshots</id>
<name>Codehaus snapshots</name>
<url>http://snapshots.repository.codehaus.org/
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

Which is copied from a setting in my work PC settings.xml. I don't think
it should be there at all. Maven ends up copying the latest version of
the plugin, or trying to anyway, since there is no 1.1-SNAPSHOT release,
only a timestamped jar:

http://snapshots.repository.codehaus.org/org/codehaus/mojo/sql-maven-plugin/1.1-SNAPSHOT/sql-maven-plugin-1.1-20070221.045741-1.jar

<http://snapshots.repository.codehaus.org/org/codehaus/mojo/sql-maven-plugin/1.1-SNAPSHOT/sql-maven-plugin-1.1-20070221.045741-1.jar>


Ah, better. It works now, but I had to move up a directory to
/spring-ws/samples/airline/

But wait... there's more:

me@homer /spring-ws/samples/airline
$ mvn -P hsqldb sql:execute
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'sql'.
[INFO]
-------------------------------------------------------------------------
---
[INFO] Building Spring WS Airline Sample
[INFO] task-segment: [sql:execute]
[INFO]
-------------------------------------------------------------------------
---
[INFO] [sql:execute]
[INFO] Executing file:
d:\work\careerone\spring-ws\samples\airline\src\main\sql\
hsqldb\airline-schema.sql
[INFO] Executing file:
d:\work\careerone\spring-ws\samples\airline\src\main\sql\
airline-dataload.sql
[INFO] 18 of 18 SQL statements executed successfully
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu May 31 04:56:53 EST 2007
[INFO] Final Memory: 2M/4M
[INFO]
------------------------------------------------------------------------


Good. But then.

me@homer /spring-ws/samples/airline
$ mvn -P hsqldb jetty:run
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-surefire-plugin' does
not exis
t or no valid version could be found
[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu May 31 04:58:12 EST 2007
[INFO] Final Memory: 1M/4M
[INFO]
------------------------------------------------------------------------

Okay, try it with -e parameter.

me@homer /spring-ws/samples/airline
$ mvn -P hsqldb jetty:run -e
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-surefire-plugin' does
not exis
t or no valid version could be found
[INFO]
------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: The plugin
'org.apache.m
aven.plugins:maven-surefire-plugin' does not exist or no valid version
could be
found
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(Defa
ultLifecycleExecutor.java:1286)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor
(DefaultLifecycleExecutor.java:1469)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListBy
AggregationNeeds(DefaultLifecycleExecutor.java:386)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:138)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:272)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at
org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by:
org.apache.maven.plugin.version.PluginVersionNotFoundException: The p
lugin 'org.apache.maven.plugins:maven-surefire-plugin' does not exist or
no vali
d version could be found
at
org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePl
uginVersion(DefaultPluginVersionManager.java:228)
at
org.apache.maven.plugin.version.DefaultPluginVersionManager.resolvePl
uginVersion(DefaultPluginVersionManager.java:90)
at
org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPlug
inManager.java:166)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(Defa
ultLifecycleExecutor.java:1257)
... 14 more
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu May 31 04:58:22 EST 2007
[INFO] Final Memory: 1M/3M
[INFO]
------------------------------------------------------------------------

Isn't maven-surefire-plugin one of the core plugins that maven is
supposed to already know about?

AAAAAARGH. Tried running it with -e -X parameter. Lightbulb moment.
Again, a wayward setting I pasted from somewhere else that screwed
things up for maven.

In trying to fix the sql-maven-plugin issues, I had placed these
settings in, but forgot to replace them with appropriate values.

<profiles>
<profile>
<id>my-snap-repo-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>my-snap-repo</id>
<name>My In-House SNAPSHOT Repository</name>
<url>http://www.my-server.com/maven-snap
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>my-snap-plugin-repo</id>
<name>My In-House SNAPSHOT Plugin Repository</name>
<url>http://www.my-server.com/maven-snap
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>interval:15</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

running it with -X then showed the problem:

[INFO] Searching repository for plugin with prefix: 'jetty'.
[DEBUG] Skipping disabled repository my-snap-plugin-repo
[DEBUG] Skipping disabled repository my-snap-plugin-repo
[DEBUG] Skipping disabled repository my-snap-plugin-repo
[DEBUG] maven-compiler-plugin: resolved to version 2.0.2 from repository
central

[DEBUG] Retrieving parent-POM: org.apache.maven.plugins:maven-plugins::8
for pro
ject: null:maven-compiler-plugin:maven-plugin:2.0.2 from the repository.
[DEBUG] Retrieving parent-POM: org.apache.maven:maven-parent::5 for
project: org
.apache.maven.plugins:maven-plugins:pom:8 from the repository.
[DEBUG] Retrieving parent-POM: org.apache:apache::3 for project:
org.apache.mave
n:maven-parent:pom:5 from the repository.
[DEBUG] Skipping disabled repository my-snap-plugin-repo
[DEBUG] maven-surefire-plugin: using locally installed snapshot
[DEBUG] Artifact not found - using stub model: Unable to determine the
latest ve
rsion

org.apache.maven.plugins:maven-surefire-plugin:pom:LATEST


[DEBUG] Using defaults for missing POM
org.apache.maven.plugins:maven-surefire-p
lugin:pom:LATEST
[DEBUG] maven-surefire-plugin: using locally installed snapshot
[DEBUG] Artifact not found - using stub model: Unable to determine the
release v
ersion

org.apache.maven.plugins:maven-surefire-plugin:pom:RELEASE


[DEBUG] Using defaults for missing POM
org.apache.maven.plugins:maven-surefire-p
lugin:pom:RELEASE
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-surefire-plugin' does
not exis
t or no valid version could be found
[INFO]
------------------------------------------------------------------------

So eventually, Maven decides "OK, I'll just go find the RELEASE version
of maven-surefire-plugin, but then it's pointing to a nonsense plugin
repository. Which still doesn't make sense because that plugin
repository is supposed to be disabled. So does this mean having a
setting in there disables Maven from doing any further searches on the
main repo1.maven.org repository? Looks like it.

Nah, that wasn't the problem. The problem was the version I have
installed locally - it looks like when I installed it manually, it
didn't get set up with any version info, so the metadata.xml for that
and maven-resources plugin reads:

<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</metadata>

and

<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</metadata>

The fix? Remove those installed jars and just let maven re-fetch them
from the repository.

Maven then re-installed these plugins and we now have:

<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.1.3</version>
<versioning>
<latest>2.3</latest>
<release>2.3</release>
<versions>
<version>2.0-beta-1</version>
<version>2.0</version>
<version>2.1</version>
<version>2.1.1</version>
<version>2.1.2</version>
<version>2.1.3</version>
<version>2.2</version>
<version>2.3</version>
</versions>
<lastUpdated>20070301014816</lastUpdated>
</versioning>
</metadata>

and

<?xml version="1.0"?><metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<versioning>
<latest>2.2</latest>
<release>2.2</release>
<versions>
<version>2.0-beta-1</version>
<version>2.0-beta-2</version>
<version>2.0</version>
<version>2.1</version>
<version>2.2</version>
</versions>
<lastUpdated>20060514041911</lastUpdated>
</versioning>
</metadata>


Finally got the sample app running. Looks like installing a plugin
without version number (eg, the -Dversion parameter) caused that last error.

No comments: