I’m a software engineer. I got my first computer when I was 7 and have loved programming ever since. I’ve been developing corporate web applications since 1999, mostly using Java based technologies, but I like to try and explore a little bit of everything interesting going around the web/mobile technology scene. I like hard rock, RPG video games (all flavors), science fiction and fantasy books, and almost all movies (unless they star Sandra Bullock or Hugh Grant). Ricardo is a DZone MVB and is not an employee of DZone and has posted 16 posts at DZone. You can read more from them at their website. View Full User Profile

Using an Authenticated Maven Repo in Play 2.0

  • submit to reddit

We have an internal Maven repo/mirror in my company, we use it to host the releases of our internal apps and libraries, as well as to mirror all the external packages we use (this speeds up build times, new environments set-ups and reduces bandwidth use).

Our internal repository requires authentication to both read/download packages and to publish new releases.

Play 2.0 provides built-in support for Maven repositories, and it’s quite straightforward to add new ones, but how to configure and use an authenticated one wasn’t documented (at least as far as I could see on the official Play website).

Long story short, what you need to do to get this scenario up and running is add the highlighted line to your /project/Build.scala file:

import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
    val appName         = "spei"
    val appVersion      = "1.0-SNAPSHOT"
    val appDependencies = Seq()
    Credentials.add(Path.userHome / ".mavencredentials", null)
    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
      resolvers += "My Custom Repo" at "http://mymavenhost/my/maven/repo/path/"

The path you pass to the Credentials.add() method can be anything, I chose ~/.mavencredentials arbitrarily. These file must contain the following info:

realm=My HTTP authentication realm

The realm parameter must match the HTTP auth realm name your web server publishes when requesting authentication.

Note that you can also use a variation of the Credentials.add() method that receives the information directly (ie. without using an external file), but since this promotes hard-coding credentials in your application I really don’t recommend it.

After that just perform an update within your projects play console and it should pull the new dependencies from your configured Maven repo.





Published at DZone with permission of Ricardo Zuasti, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)