Over a million developers have joined DZone.

Using an Authenticated Maven Repo in Play 2.0

DZone 's Guide to

Using an Authenticated Maven Repo in Play 2.0

· Java Zone ·
Free Resource

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

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}