6

私の Play 2 アプリケーションは、より大きな Maven アプリケーションのサブプロジェクトです。Play 2 アプリには、その親に依存関係があります。親からデータ アクセスを取得します。したがって、アプリケーションの Build を外部の Maven プロジェクトに依存させたいと考えています。

基本的に、私はこれを書きたいです:

val main = play.Project(appName, appVersion, appDependencies).settings(
   // settings
).dependsOn(externalPom(baseDirectory(_ / "../pom.xml")))

しかしもちろん、これは有効な構文ではありません。

私はplay.Projectこのように自分を定義しようとしました:

val main = play.Project(appName, appVersion, appDependencies).settings(
   externalPom(baseDirectory(_ / "../pom.xml"))
)

(私が思うに)オーバーライドによりPlayが独自の例外をロードしないため、これは失敗します

私は次のProjectように新しいものを定義しようとしました:

lazy val data = Project("data", file(baseDirectory(_ / "..).settings(
   externalPom(baseDirectory(_ /         "../pom.xml"))
)

それに応じて、メインクラスが検出されないため、これは機能しません。

これを行う方法に関する提案はありますか?私はSBTが初めてです。

4

2 に答える 2

0

play2-maven-plugin の使用に成功しています

http://nanoko-project.github.io/maven-play2-plugin/maven/release/

このプラグインを使用して、play2 アプリ用の maven モジュールも作成し、maven pom で依存関係 (データ アクセス レイヤー) を定義します。プラグインは、play が依存関係を確実に取得できるようにします (pom 依存関係を lib ディレクトリの管理されていない依存関係にコピーします)。

このプラグインを使用すると、1 つのプロジェクトにすべてが含まれるため、多くの面倒な再構築を回避できます。そのため、IDE は再構築なしですべてのモジュールの変更を確認できます。

また、プラグインを使用する場合、ローカルの Maven リポジトリからスナップショットの Maven 依存関係を更新しても問題はありません (この sbt バグhttps://github.com/sbt/sbt/issues/321 )。

于 2013-10-09T15:21:49.130 に答える
0

play2-maven-pluginsbt-pom-readerでこれを行いました。

play2-maven プロジェクトを次のように構成する必要があります。

<my-maven-project>/
  pom.xml                  <- Your maven build
  build.sbt                <- the sbt Play 2 configuration
  project/
     build.properties      <- the sbt version specification
     build.scala           <- the sbt build definition
     plugins.sbt           <- the sbt plugin configuration

  ..                       <- Whatever files are normally in your maven project.

各ファイルには、次の内容が含まれている必要があります。

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.foo</groupId>
    <artifactId>bar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>play2</packaging>
    <name>My mavenified Play 2 application</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <play2.version>2.2.1</play2.version>
        <play2-scala.version>2.10</play2-scala.version>
        <play2.plugin.version>1.0.0-alpha5</play2.plugin.version>
        <scala.version>2.10.2</scala.version>
    </properties>
    <repositories>
        <repository>
            <id>typesafe</id>
            <name>Typesafe - releases</name>
            <url>http://repo.typesafe.com/typesafe/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play_${play2-scala.version}</artifactId>
            <version>${play2.version}</version>
        </dependency>
        <!-- only if using Java -->
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-java_${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>
        <!--<outputDirectory>target/scala-${play2-scala.version}/classes</outputDirectory>-->
        <plugins>
            <plugin>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <version>${play2.plugin.version}</version>
                <extensions>true</extensions>
                <dependencies>
                    <dependency>
                        <groupId>com.google.code.play2-maven-plugin</groupId>
                        <artifactId>play2-provider-play22</artifactId>
                        <version>${play2.plugin.version}</version>
                    </dependency>
                </dependencies>
                <!-- only if using Java -->
                <configuration>
                    <mainLang>java</mainLang>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

build.sbt:

play.Project.playJavaSettings //or play.Project.playScalaSettings

プロジェクト/build.properties:

sbt.version=0.13.0

プロジェクト/build.scala:

object BuildFromMavenPomSettings extends com.typesafe.sbt.pom.PomBuild

プロジェクト/plugins.sbt:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-pom-reader" % "1.0.1")
于 2014-03-18T15:34:30.787 に答える