My Apache Archiva setup for sbt

Posted on January 28, 2015 by Stefan Bleibinhaus

This blog post describes my Apache Archiva [1] setup with nginx [2] on bleibinha.us/archiva [3] . I use it as a build artifact repository for my Scala [4] projects built by sbt [5] . This post also describes how I modify my sbt projects to deploy successfully to Archiva.


1 Installing Apache Archiva

The following steps describe how to install Apache Archiva 2.1.1 [1] on a Linux server. It will be started by the non-login user archiva and will be set to run on the non-default port 8083 (instead of 8080).

  • Switch to the root user sudo -s su
  • Create the non-login user archiva: useradd -r archiva
  • Download the Archiva standalone version wget http://apache.mirror.rafal.ca/archiva/2.1.1/binaries/apache-archiva-2.1.1-bin.zip
  • Unzip the archive unzip apache-archiva-2.1.1-bin.zip
  • Move Archiva to the home directory of the archiva user: cd /home && mkdir archiva && cd archiva && mv /root/apache-archiva-2.1.1 . && cd ..
  • Make archiva the owner of the directory and its content chown -R archiva:archiva archiva
  • Change the default port by opening cd archiva/apache-archiva-2.1.1/conf && vim jetty.xml and then chaning the SystemProperty with name jetty.port to default 8083 (or the port you prefer)
  • Set the context path to /archiva/ with cd ../contexts && vim archiva.xml (Makes it easier to configure nginx right)
  • Make sure Archiva gets started by the right user with cd ../bin && vim archiva and then set RUN_AS_USER=archiva
  • Add Archiva to the startup scripts with cd /etc/init.d && ln -s /home/archiva/apache-archiva-2.1.1/bin/archiva archiva
  • Start Archiva on startup of the server with cd /etc/cron.d && vim job and add the line @reboot root service archiva start

Now Archiva can be started with service archiva start. After starting it, browse to host:8083/archiva and configure it to your needs. I have done the following:

  • Create an admin account
  • UI Configuration: Set application link, disable registration link
  • Disable guest to access internal
  • Allow SNAPSHOTs in internal
  • Add releases repo

2 Configure nginx

Edit nginx.conf and include inside the server block the proxypass seen in Code snippet 1. Then reload nginx with nginx -s reload. Afterwards your Archiva instance should be proxypassed over nginx. My instance is running on bleibinha.us/archiva [3] .

Code snippet 1: Nginx proxypass for Archiva.

3 Sbt publishing

For publishing using sbt (0.13.7) [5] to your freshly created Archiva instance, take a look at the sbt docs for publishing [6] to get a basic understanding of the publish task in sbt. Personally I use code seen similar to the one seen in Code snippet 2. My credential files look like the ones seen in Code snippet 3. It is important to get the realm attribute right as it is a common source of error [7] . For publishing snapshot versions correctly with sbt, projects currently have to use sbt-aether-deploy [8] 1. Sbt also allows to build for different Scala versions using sbt Cross-build [11] : crossScalaVersions := Seq("2.10.4", "2.11.5"). For a complete example check out the build.sbt [12] file of my akka-actor-locking lib [13] . The published artifacts can be resolved in other projects as seen in Code snippet 4.

Code snippet 2: The publishing part of the build.sbt file [12] in akka-actor-locking [13] .
Code snippet 3: My archiva credential files.
Code snippet 4: Adding akka-actor-locking [13] to a project's build.sbt.

1 This will hopefully fixed soon as sbt is gradually moving [9] towards aether [10] .


comments powered by Disqus
Admin login