Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. 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
host=mymavenhost
user=john
password=trustno1

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.

 

 

 

 

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}