简体   繁体   English

使用Play和IntelliJ的多个项目

[英]Multiple Projects Using Play and IntelliJ

I have a Play 2.2 project and am using IntelliJ 12. I generated the project files by doing play idea from the command line. 我有一个Play 2.2项目,并且正在使用IntelliJ12。我通过从命令行执行play idea生成了项目文件。 (The play2 plugin is so poor I have to do this every time I change a dependency, which is pretty remarkable considering I paid for 'ultimate' to have Play support). (play2插件太差了,我每次更改依赖项时都必须这样做,考虑到我为“最终”获得了Play支持而付出了代价,这是非常出色的) Anyway, the question is now I want to have more modularity as the project grows. 无论如何,现在的问题是我希望随着项目的发展具有更多的模块化。 I want to have several projects that compile to jars. 我想要几个可以编译为jar的项目。 (I'm doing this in part because the scala compile times make TDD excruciating.) (我之所以这样做,部分原因是scala的编译时间使TDD难以承受。)

In eclipse, I would simply make a workspace and then make those projects all hang off of a pom project. 在eclipse中,我将简单地创建一个工作区,然后使那些项目都挂在pom项目之外。 If I do the same thing here, how am I going to get the intellij project files for the play project? 如果我在这里做同样的事情,我该如何获取play项目的intellij项目文件? It will only generate them in the directory of the play project. 它将仅在play项目的目录中生成它们。

I have a Play 2.2 project that I split at my work here is what I did: 我有一个Play 2.2项目,我在这里从事的工作是:

Folder Structure: 资料夹结构:

Project: 项目:

  project1
    --project/Build.scala
  project2
    --project/Build.scala
  project3
    --project/Build.scala

project/Build.scala

Here is how the main Build.scala looks like: 这是主要Build.scala的样子:

import sbt._
import Keys._

object ApplicationBuild extends Build {

  val appName = "test"
  val appVersion = "test-0.1"
  val ScalaVersion = "2.10.2"

  val appDependencies = Seq(    
  )

  lazy val project1 = RootProject(file("./project1/"))

  lazy val project2 = RootProject(file("./project2/"))

  lazy val project3 = RootProject(file("./project3/"))

  lazy val mainProject = Project (
    id = "test",
    base = file("."),
    settings = Project.defaultSettings).settings(    
      scalaVersion := ScalaVersion,
      name := appName,
      version := appVersion,
      resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/maven-releases/",
      resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
      resolvers += "Typesafe snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
      resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
      libraryDependencies ++= appDependencies

    ).aggregate(project1).aggregate(project2).aggregate(project3)

}

This will be the mean sbt Build file that will build all your sub-projects. 这将是将构建所有子项目的平均sbt Build文件。

Here is how project2's Build.scala file looks like (in this case this is the Play project) 这是project2的Build.scala文件的外观(在本例中为Play项目)

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

object ApplicationBuild extends Build {

  val appName = "project2"
  val appVersion = "1.0"



  val appDependencies = Seq(
    jdbc       
  )


  lazy val project1 = RootProject(file("../project1"))

  lazy val main = play.Project(appName, appVersion, appDependencies).settings(
    scalaVersion := "2.10.2",
    resolvers += Resolver.url("typesafe", url("http://repo.typesafe.com/typesafe/releases/")),
    resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
  ).dependsOn(project1)

}

Basically project2 depends on project1's code. 基本上project2取决于project1的代码。

I would then edit the main project/plugins.sbt file and add the sbt plugin Instructions here: https://github.com/mpeltonen/sbt-idea (I use the snapshot version) 然后,我将编辑主项目/plugins.sbt文件并在此处添加sbt插件说明: https : //github.com/mpeltonen/sbt-idea (我使用快照版本)

Then generate the intellij project by using the gen-idea command. 然后使用gen-idea命令生成intellij项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM