LoginSignup
1
1

More than 5 years have passed since last update.

[Play 2.5] サブプロジェクトの作成

Posted at

参照:
https://www.playframework.com/documentation/2.5.x/SBTSubProjects

サブプロジェクト用ディレクトリの準備

ディレクトリ構造は、
https://www.playframework.com/documentation/2.5.x/SBTSubProjects
に記載されている通り、下記のようになる。

build.sbt
app
  └ controllers
  └ models
  └ views
conf
  └ application.conf
  └ routes
modules
  └ core
    └ build.sbt
    └ conf
      └ core.routes
    └ app
      └ controllers
      └ models
      └ views
project
  └ build.properties
  └ plugins.sbt

自分のプロジェクトの場合はまずcoreというサブプロジェクトを作りたかったので、名前がcoreになっているが、自分の作りたいサブプロジェクト名を使う。

サブプロジェクトにbuild.sbtを追加する

coreディレクトリ下にbuild.sbtを下記のように作成。

name := """core"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.7"

プロジェクト全体のbuild.sbtの編集

プロジェクト全体のbuild.sbtに下記を追加する。

lazy val core = (project in file("modules/core"))
    .enablePlugins(PlayScala)
    .enablePlugins(SbtWeb)

lazy val root = (project in file("."))
    .enablePlugins(PlayScala)
    .enablePlugins(SbtWeb)
    .dependsOn(core) // メインプロジェクトのクラスパスにサブプロジェクトを追加する。
    .aggregate(core) // コンパイルやテストなどを、ベースプロジェクトで実行する時に、サブプロジェクトも実行する。

ベースプロジェクトのroutesにサブプロジェクトのroutesをインポートする。

ベースプロジェクトのroutesファイルに下記のようにサブプロジェクトのroutesをインポートする。

-> / core.Routes

これで、サブプロジェクトのcore.routesが使えるようになる。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1