3

i'm currently working on a Play ! 2.1.1 application defining multiple subprojects. Here is my Build.scala :

val lfamName = "lfam"
val lfamVersion = "1.0-SNAPSHOT"
val lfamDirectory = "subprojects/" + lfamName
lazy val lfam = play.Project(lfamName, lfamVersion, appDependencies, path = file(lfamDirectory))

val mainName = "main"
val mainVersion = "1.0-SNAPSHOT"
lazy val main = play.Project(mainName, mainVersion, appDependencies)
            .settings().dependsOn(lfam).aggregate(lfam)

The resulting struture :

app
  └ controllers
    └> Application.scala
  └ models
  └ views
    └> index.scala.html
  └ assets
    └ stylesheets
      └> main.less
conf
  └> application.conf
  └> routes
subprojects
  └ lfam
    └ conf
      └> lfam.routes
    └ app/controllers
      └> Application.scala
      └> Assets.scala
    └ app/models
    └ app/views
      └> index.scala.html
    └ assets
      └ stylesheets
        └> main.less

The sources :

routes

GET     /                           controllers.Application.index

-> /lfam lfam.Routes

GET     /assets/*file               controllers.Assets.at(path="/public", file)

lfam.routes

GET     /                           controllers.lfam.Application.index

GET     /assets/*file               controllers.lfam.Assets.at(path="/public", file)

Assets.scala

package controllers.lfam
object Assets extends controllers.AssetsBuilder

Application.scala (just the package name changes between project)

package controllers(.lfam)

import play.api._
import play.api.mvc._

object Application extends Controller {

  def index = Action {
    Ok(views.html.index())
  }

}

main.less (main project)

@main-color: #0000ff;

h1 {
  color: @main-color;
}

main.less (lfam project)

@main-color: #ff0000;

h1 {
  color: @main-color;
}

index.scala.html (main project)

<!DOCTYPE HTML>
<html>
    <head>
        <link rel="stylesheet" href="@routes.Assets.at("stylesheets/main.css")">
    </head>
    <body>
        <h1>Header</h1>
    </body>
</html>

index.scala.html (lfam project)

<!DOCTYPE HTML>
<html>
    <head>
        <link rel="stylesheet" href="@lfam.routes.Assets.at("stylesheets/main.css")">
    </head>
    <body>
        <h1>Header</h1>
    </body>
</html>

When the subproject index is displayed (/lfam/) the header is still blue. But if i rename the main.less file from subproject to lfam.less (and the corresponding in html) the header becomes red(as expected).

Is it possible to have multiple assets in multiple subprojects, with the same name ? How is play not serving me the right css file in the first case but finding the second one ?

Thanks

4

1 回答 1

1

这是不可能的,因为多项目设置中的所有项目都使用相同的类加载器

ClassLoader.getResource 使用(source)加载资产。就像 Java 源代码一样,完全限定的资源名称必须是唯一的。

于 2014-01-27T21:19:35.880 回答