Pergunta

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. (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). 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. (I'm doing this in part because the scala compile times make TDD excruciating.)

In eclipse, I would simply make a workspace and then make those projects all hang off of a pom project. If I do the same thing here, how am I going to get the intellij project files for the play project? It will only generate them in the directory of the play project.

Foi útil?

Solução

I have a Play 2.2 project that I split at my work here is what I did:

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:

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.

Here is how project2's Build.scala file looks like (in this case this is the Play project)

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.

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)

Then generate the intellij project by using the gen-idea command.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top