Saturday, December 11, 2010

Set up a Maven Repository Manager

My basic requirements are
  1. rich and intuitive user interface
  2. ease of setting network proxy
  3. ease of deploying 3rd party and internal artifacts
I got a chance to try several different products and finally installed one of them. Here are my impressions and the problems I encountered and luckily fixed.

Sonatype Nexus
No one can ignore it. De facto standard and from the company behind Maven. It's not my first time to use the interface, so no surprise and everything works just as expected.

JFrog Artifactory
I had to say I love the design, and the auto discovery of ArtifactId, Version and Type during deploying artifacts, although some GroupId are wrongly set to be the same as ArtifactId.

Apache Archiva
It has quite good UI, but needs work on usabilities. If you have several remote repositories and need to apply the same (is there anyone need to set different proxies?) network proxy, it's a joke. Also it lacks some commonly used artifacts, which the other two players have no such problem.

I tried each of them for half day or so and decided to go with Artifactory.

Problem
Downloading: http://localhost:8081/artifactory/repo/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.jar

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-compiler-plugin:2.3.2: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2 in artifactory (http://localhost:8081/artifactory/repo)

Solution
Set network proxy.

Problem
[WARNING] While downloading poi:poi:3.1-FINAL

This artifact has been relocated to org.apache.poi:poi:3.1-FINAL.

Solution
It's not repository manager's problem and it's better to follow the new location defined in pom file.

Problem
HTTP ERROR 409

Problem accessing /artifactory/repo/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2.pom. Reason:

Rejected artifact download request: Checksum policy 'GEN_IF_ABSENT' rejected the artifact 'commons-fileupload-1.2.2.pom'. Checksums info: [ChecksumInfo{type=SHA-1, original='ad3fda4adc95eb0d061341228cc94845ddb9a6fe', actual='0ce5d4a03b07c8b00ab60252e5cacdc708a4e6d8'}, ChecksumInfo{type=MD5, original='c938bb047b88d2b85b47da0be9d901ec', actual='b219248b081b6b44abf436f41e16e9e1'}]

Solution
Go to Configure Repositories, in Edit Remote Repository, change Checksum Policy from default "Generate if absent" to "Ignore and generate".

Problem
HTTP ERROR 409

Problem accessing /artifactory/repo/velocity/velocity/1.5/velocity-1.5.pom. Reason:

The target deployment path 'velocity/velocity/1.5/velocity-1.5.pom' does not match the POM's expected path prefix 'org/apache/velocity/velocity/1.5'. Please verify your POM content for correctness and make sure the source path is a valid Maven 2 repository root path.

Solution
This is not repository manager's problem. Change the dependency definition as suggested.

Problem
HTTP ERROR 404

Problem accessing /artifactory/repo/hsqldb/hsqldb/1.8.0.2/hsqldb-1.8.0.2.pom. Reason:

Could not find resource

Solution
None of the default remote repositories has this artifact. Add a remote repository (in this case, http://repository.jboss.org/maven2/) and assign it to remote-repos.

Problem
Error messages in Maven Console in Eclipse
Unable to update index for snapshots|http://localhost:8081/artifactory/plugins-snapshot: Resource nexus-maven-repository-index.properties does not exist

Updating index central|http://localhost:8081/artifactory/plugins-release

Unable to update index for central|http://localhost:8081/artifactory/plugins-release: Resource nexus-maven-repository-index.properties does not exist

Updating index snapshots|http://localhost:8081/artifactory/libs-snapshot

Unable to update index for snapshots|http://localhost:8081/artifactory/libs-snapshot: Resource nexus-maven-repository-index.properties does not exist

Updating index central|http://localhost:8081/artifactory/libs-release

Unable to update index for central|http://localhost:8081/artifactory/libs-release: Resource nexus-maven-repository-index.properties does not exist

Updating index snapshots|http://localhost:8081/artifactory/plugins-snapshot

Solution
Maven Settings Generator generated wrong URLs in settings.xml. Use following URLs instead.
<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>libs-releases</name>
        <url>http://localhost:8081/artifactory/libs-release-local</url>
    </repository>
    <repository>
        <snapshots />
        <id>snapshots</id>
        <name>libs-snapshots</name>
        <url>http://localhost:8081/artifactory/libs-snapshot-local</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>plugins-releases</name>
        <url>http://localhost:8081/artifactory/plugins-release-local</url>
    </pluginRepository>
    <pluginRepository>
        <snapshots />
        <id>snapshots</id>
        <name>plugins-snapshots</name>
        <url>http://localhost:8081/artifactory/plugins-snapshot-local</url>
    </pluginRepository>
</pluginRepositories>

Monday, November 29, 2010

How to migrate an SVN repository

I had a chance to migrate an SVN repository of more than 10,000 revisions to another machine. Here are the process and the problems I solved.

1. Install a new Subversion server
CollabNet Subversion Edge 1.3 for Windows 64-bit is chosen because it has great web user interface to manage repositories and users.

2. Dump old repository
This should be very easy by using
svnadmin dump path/to/repository > repository.dump

But I got errors like
svnadmin: Filesystem path .../trunk/... is neither a file nor a directory

This is because either the file system or the repository is corrupt. I had to spit the dumping at the failing revision. Any dumpings after the failing point should use --incremental option.
svnadmin dump -r 0:N-1 path/to/repository > 0_N-1.dump
svnadmin dump --incremental -r N+1:M path/to/repository > N+1_M.dump

3. Create new repository
This can be done in 2 ways.
svnadmin create path/to/repository
or
New Repository in Repositories category in Subversion Edge's web UI (http://host:3343/csvn/repo/create).

Note, however, that you have to uncheck "Create standard trunk/branches/tags structure" in Use template option. Otherwise you will get following error when loading the dumped repository.
adding path : branches ...svnadmin: File already exists: filesystem '..\data\repositories\repository\db', transaction '123-4l', path 'branches'

4. Load dumped repository (for me, repositories)
Remember to use --force-uuid when you load the repository, or you may suffer either the above error or difficulties in relocate you old repository to new one.
svnadmin load --force-uuid path/to/repository < repository.dump

If you have failures in dumping like me. You have to replicate what the failing revision is supposed to be doing, and check in the changes to revision N in my example.

Hope it's helpful to Subversion users, but maybe migrate to Git is the way to go.