Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

integration of sbt (play!) project with maven parent pom

I have a maven project with multiple maven modules organized around parent pom. All these modules are packaged into JAR files which are dependencies of my Play! application built as a SBT project:

MyProject
-> pom.xml (parent)
MavenModule1
  -> pom.xml (child pom)
MavenModule2
  -> pom.xml (child pom)
PlayApplication
  -> Build.scala (SBT project)

Since all maven modules are child projects of parent module (MyProject), I can go to 'MyProject', execute mvn clean install and entire project, except PlayApplication will be built. The question is how can I modify parent pom/SBT build file to fire PlayApplication build together with the rest of modules?

(I know that probably there is no simple, build-in way to do it, so all hacks are welcomed :))

like image 496
woof-woof Avatar asked Jun 16 '13 21:06

woof-woof


1 Answers

Use play2-maven-plugin - you can compile project as normal maven project.

Example of Build.scala (all changes should be synchronized between pom and Build.scala)

import sbt._
import Keys._
import play.Project._
import Path._

object ApplicationBuild extends Build {

  val myExternalPom = super.settings ++ externalPom(baseDirectory(_ / "pom.xml"))
  val appName         = "PlayApplication"
  val appVersion      = "1.0.0"

  val appDependencies = Seq(
    jdbc,
    anorm
  )


  val main = play.Project(appName, appVersion, appDependencies,file(".")).settings(
    resolvers ++= Seq( "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
      , "central" at "http://artifactory:8081/artifactory/libs-release")
  ).settings(
    externalPom() :_*
  )

}

Pom file

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>play2</packaging>

    <name>Play! Framework 2.x Maven Test Project</name>

    <repositories>
        <repository>
            <id>typesafe</id>
            <name>Typesafe - releases</name>
            <url>http://repo.typesafe.com/typesafe/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <play2.plugin.version>1.0.0-alpha1</play2.plugin.version>
        <play2.version>2.1.0</play2.version>
        <play2-scala.version>2.10</play2-scala.version>
        <scala.version>2.10.0</scala.version>
    </properties>
    <parent>
        <groupId>com.company.project</groupId>
        <artifactId>my-parent-pom</artifactId>
        <version>1.0.0</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>play</groupId>
            <artifactId>play_${play2-scala.version}</artifactId>
            <version>${play2.version}</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>${basedir}/app</sourceDirectory>
        <resources>
            <resource>
                <directory>${basedir}/conf</directory>
            </resource>
            <resource>
                <directory>${basedir}</directory>
                <includes>
                    <include>public/**</include>
                </includes>
            </resource>
        </resources>
        <directory>${basedir}/target/scala-${play2-scala.version}</directory>
        <plugins>
            <plugin>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <version>1.0.0-alpha1</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

Move all dependencies from Build.scala to pom file. Maven do not know about Build.scala (I do not test it)

NOTE

If you use the eclipse IDE (scala-ide) - please run command: play eclipse always when you update pom file. This command updates .classpath . In idea I think dependencies are update automatically.

UPDATE
Add <directory>${basedir}/target/scala-${play2-scala.version}</directory> to pom file. Play by default compile all to this directory (problem in idea).

FOR IDEA COMMUNITY VERSION
You can use idea without play plugin - import your project as maven project to idea. Do not call play idea before.

like image 85
Andrzej Jozwik Avatar answered Nov 01 '22 07:11

Andrzej Jozwik