2005-10-26

More Maven findings. I've said before that in my humble opinion, Maven is too much in a state of flux to start using it in projects. I think this shows itself when you encounter older Maven projects, especially on the subject of repositories.

Maven uses repositories, where jars are kept. Those jars can be your own or someone else's. There are two types of repositories, local and remote. Local means on your own disk. Remote means ibiblio and your organization's repository. When the documentation talks about central repositories, they mostly mean remote repositories.

You'll probably want to use goal "jar:deploy" to copy your jars, wars and ears (artifacts in Maven-speak) via scp or sftp to some central box, your own organization's remote repository. Update: sftp might not work for you, see 2005-11-04

These need to be defined in your project.properties, see the Maven documentation on internal repositories:

  maven.repo.list=myrepo
  maven.repo.myrepo=scp://repository.mycompany.com/
  maven.repo.myrepo.directory=/www/repository.mycompany.com/
  maven.repo.myrepo.username=${user.name}
  maven.repo.myrepo.privatekey=${user.home}/.ssh/id_dsa

This way, everyone can deploy using his own username. This has the following advantages:

  1. You don't need to set up a generic account with a shared password
  2. You can always trace back a release to a specific user, which is useful when there are problems and you know how the build was done

Of course, there's a catch. You have to force everyone to have the same key name, and some users called it id_rsa or privatekey or cheese_sandwich. Maven can't figure this out itself, just like standard ssh does. We're helping it: create a file in your home directory called build.properties and add the following line to it:

  maven.privatekey=/home/user/.ssh/myprivatekey

And edit the line in your project.properties to read:

  maven.repo.myrepo.privatekey=${maven.privatekey}

There are also the following properties, which are deprecated and shouldn't be used. I encountered them in an older project along with the above properties and it took me a while to find out they're documented in the Maven properties documentation:

  maven.repo.central=repository.mycompany.com
  maven.repo.central.directory=/www/repository.mycompany.com/

Note how the documentation above all the options says this stuff is deprecated, and then continues to say in the description for each option that it's deprecated and you should use deploymentAddress and deploymentDirectory in project.xml. Read on and shiver: those are deprecated as well. Deprecation upon deprecation, welcome to Maven!

Anyway, the myrepo directory should be published with an Apache or similar webserver, and the URL to reach that particular directory should be put in the remote repository properties

  maven.repo.remote=http://www.ibiblio.org/maven,
    http://repository.mycompany.com/maven

N.B. Don't confuse all this stuff with the elements <siteAddress> and <siteDirectory> in your project.xml, these are used by the goal "site:deploy".