Over a million developers have joined DZone.

Using an Authenticated Maven Repo in Play 2.0

· Java Zone

Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems, brought to you in partnership with AppDynamics.

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.





The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.


Published at DZone with permission of Ricardo Zuasti, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}