将sbt(play!)项目与maven父pom集成

时间:2013-06-16 21:34:51

标签: maven build sbt playframework-2.1

我有一个maven项目,其中包含围绕父pom组织的多个maven模块。所有这些模块都打包成JAR文件,这些文件是我Play的依赖项!作为SBT项目构建的应用程序:

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

由于所有maven模块都是父模块(MyProject)的子项目,我可以转到'MyProject',执行mvn clean install和整个项目,但PlayApplication除外。 问题是如何修改父pom / SBT构建文件以与其余模块一起触发PlayApplication构建?

(我知道可能没有简单的,内置的方式来做到这一点,所以欢迎所有的黑客:))

1 个答案:

答案 0 :(得分:9)

使用play2-maven-plugin - 您可以将项目编译为普通的maven项目。

Build.scala示例(所有更改应在pom和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文件

<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>

将所有依赖项从Build.scala移动到pom文件。 Maven不知道Build.scala(我不测试它)

注意

如果您使用eclipse IDE(scala-ide) - 请运行命令: 总是在更新pom文件时play eclipse。此命令更新.classpath。在想法中,我认为依赖关系会自动更新。

<强>更新
<directory>${basedir}/target/scala-${play2-scala.version}</directory>添加到pom文件中。默认播放将所有内容编译到此目录(想法中的问题)。

FOR IDEA COMMUNITY VERSION
你可以使用没有播放插件的想法 - 将你的项目作为maven项目导入到想法中。请勿在之前致电play idea