SBT集成(玩!)项目与Maven父POM [英] integration of sbt (play!) project with maven parent pom

查看:250
本文介绍了SBT集成(玩!)项目与Maven父POM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我周围父POM多次组织行家模块Maven项目。所有这些模块打包成JAR文件这是我玩的依赖!应用程序构建为SBT项目:

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)

由于所有的Maven模块是父模块的子项目(MyProject的),我可以去'MyProject的',执行 MVN全新安装和整个项目,除了PlayApplication会建成。
现在的问题是我怎么可以修改父POM /舒巴坦构建文件火PlayApplication与其余模块共同建立?

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

推荐答案

使用的 play2-Maven的插件 - 你可以编译项目正常Maven项目

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

Build.scala的示例(所有变化应该POM和Build.scala之间同步)

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

<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(我不考吧)

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

注意

如果您使用Eclipse IDE(斯卡拉-IDE) - 请运行命令:
播放蚀总是在更新POM文件。此命令更新的.classpath。在想法,我觉得依赖自动更新是

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.

更新

添加&LT;&目录GT; $ {BASEDIR} /目标/斯卡拉 - $ {play2-scala.version}&LT; /目录&GT; 来POM文件。默认情况下,玩编译所有到这个目录(在理念问题)。

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社区版

您可以使用想法不玩插件 - 导入项目作为Maven项目来的想法。不要叫打主意之前。

这篇关于SBT集成(玩!)项目与Maven父POM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆