Kevin Meredith
Kevin Meredith

Reputation: 41909

Add Play Library to Maven Project

The Play Managing library dependencies docs explain how to configure SBT to use the Play library.

But, how can I add this library to a Maven project?

I'm trying to create a Java toJson method. I'd like to use Scala Play's JSON library to do the actual conversion to JSON work. I could just return a String in my Java method, but using the JsValue type would be stronger type safety.

Upvotes: 0

Views: 1670

Answers (1)

absurdhero
absurdhero

Reputation: 356

The play json library is published to the typesafe maven repository as its own artifact. You can include it in your maven project like so:

<dependency>
    <groupId>com.typesafe.play</groupId>
    <artifactId>play-json_${play.scala.version}</artifactId>
    <version>${play.version}</version>
    <scope>compile</scope>
</dependency>

where the current value of play.scala.version as of this writing is 2.10 and play.version is 2.2.1.

If you don't use a private central repository like nexus or artifactory, add the typesafe repository to your pom by adding the following at the top level:

<repositories>
    <repository>
        <id>typesafe</id>
        <url>http://repo.typesafe.com/typesafe/releases/</url>
    </repository>
</repositories>

To see a full example of a maven pom that includes more libraries from Play, look at the sample pom included in the play-pure-maven-plugin's repository. You do not need to use the maven plugin (of which I am the author) in order to make use of these dependencies.

https://github.com/absurdhero/play-pure-maven-plugin/blob/master/sample_play_project_pom.xml

Upvotes: 4

Related Questions