« Statistically improbable phrases | Main | Maven2 repository layout document »

Maven2 and URL construction

More lessons to be learnt about web architecture. This time it's Maven2. In a Maven2 POM I have this dependency:

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>3.0.10</version>
    </dependency>

Doesn't work. I get this:

  [INFO] Main Error:
    Unable to download the artifact from any repository
    mysql:mysql-connector-java:3.0.10:jar
  from the specified remote repositories:
    http://repo1.maven.org/maven2
  Root error:
    Unable to download the artifact from any repository

The Maven2 client can't find the jar. Looking up the console I see it's trying to pull this URL down:

  [INFO] maven-compiler-plugin: resolved to version 2.0-alpha-2 from local repository
  Downloading: http://repo1.maven.org/maven2/mysql/mysql-connector-java/3.0.10/mysql-connector-java-3.0.10.jar

Some digging around shows that the jar I want is actually called mysql-connector-java-3.0.10-stable-bin.jar up on the server. The jar I need is up there, but the name is borked. The required URL is:

http://www.ibiblio.org/maven2/mysql/mysql-connector-java/3.0.10/mysql-connector-java-3.0.10-stable-bin.jar

It seems whomever built that jar stuffed more metadata into the jarname than my Maven2 client was expecting (ie it's a 'stable-bin' jar).

My answer was to download the URL and rename it in the local repository. Now, I'll have to remember not to use the -U flag in case that breaks my build. I read the Maven2 docs and nothing is jumping out at me at how to get around this - changing the version element content gets me a good jar name but breaks the preceding path.

I don't use Maven2 much, and am just tracking its progress as it goes to 1.0 as much as anything, so I don't know if this is a everyday problem [updated: a comment from Brett Porter suggest it tends to be isolated]. The POM idea is ok overall, and keeping jars out of source control is an excellent idea. But URL construction can be a fragile practice unless everyone is on board with the algorithm. Arguably, it defeats the point of trying to establish best practices for Java development and dependency management, when you don't follow best practices for the application protocol the proposed dependency management system itself depends on. There are reasons to treat URLs as opaque strings on the client rather than parameterised functions. Breakage from URL concatenation is one such reason. I wonder, if Maven2 used the DOAP format, would this problem come up, ditto for WebDAV as the protocol.

More generally the idea that this isn't documented lends weight the criticisms that plagued Maven around there being too much magic going on under the hood - or not enough. Because on the one hand its URL creation is a leaky abstraction; on the other it's not magic if it doesn't work. [updated: Steve Loughran pointed out that M2 has published their repository layout].

Finally, it's clear that the repositories are crying out for Atom feeds.


May 22, 2005 07:31 PM

Comments

Steve Loughran
(May 22, 2005 07:56 PM #)

M2 adds some extra stuff, a classifier tag, that is part of the new layout (see maven2 wiki). I dont know if the POM supports it fully yet, but all repository code should be ready for it.

Brett Porter
(May 22, 2005 11:25 PM #)

All of the elements of the URL are required for Maven's dependency management to work, so if the URL were entered most of it would be duplicate information - which would be annoying.

In general, we now vet what comes into the repository, but this JAR arrived prior to that. I was made aware of the problem with mysql-connector's filename over the weekend, and am just going out to fix it now. If you get any other problematic entries, drop us a note and it'll be sorted out promptly.

And yes, RSS feeds (as well as repository search) are on the cards.

Trackback Pings

TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1569