Play Framework project composition
Asked Answered
A

1

10

I have 2 projects, which are developed using PlayFramework 2.4. Although they are completely separate in concept, they share some common features, like evolution management (Liquibase), CRUD administrative mechanism, notification (email, sms) mechanism, etc. So, it was decided to split every project in 2 modules: common "core" module, which holds all described logic, and "project" module, which hold project-specific services, templates, views.

Recomended approach for achieving this in Play Framework is "subproject" concept. But it's clearly not an option, due to at least two reasons:

  1. Projects are developed by different teams, that's why they they can't be located in one directory structure
  2. These 3 modules ("core" and 2 "project" modules) MUST be versioned in separate VCS repos (Mercurial)

My current solution is to create core module, and provide it as a dependency in "project" Play application. An though this approach partially works, there are major downsides:

  1. If you add routes file in module, they will override project routes file
  2. You cant place views in core module, because due to fig.1 you cant access public assets
  3. Due to downside n.1 and 2, you cant place Controllers in core module, because you cant specify a view to render
  4. static assets (public directory) is not included in module distribution

I'm forced to copy common templates into both projects, I practically can't write common controllers which is annoying SO much

Appreciate any help. Maybe this can be achieved in some sort of highly-custom build and publish process for the core module?

Araxes answered 28/6, 2015 at 18:52 Comment(0)
T
1

I think you should not add the role core project as a dependency for the other 2 projects. You could break the core project into core classes and core resources. The templates and views in play framework are compiled classes, so you can pack then in a jar perfectly. The templates you create would be packaged alongside the core classes (or you can break them too). You can publish this jars into a dependency application like artifactory or nexus and import in the other projects. For the resources, you can package them like webjars do. So you can access them from any other view of your other projects.

Teteak answered 8/10, 2015 at 13:11 Comment(5)
Thank you very much, that's an interesting idea, but do you have some specific example addresing compiling and packing resources (such as views) in a separate jar?Araxes
your views should be in a separate project. how exactly yous views would be reused? about how to pack, see this: scala-sbt.org/0.12.4/docs/Detailed-Topics/Publishing.html .Teteak
Well, I have a common set of views + static assets (e.g. css, js, img) which are used by these views. And I have some core classes and controllers which invoke these views. So, my goal is to package them somehow that I would not need to copy them into all projects where i want them to be used. Actually, these views and assets form an admin interface which is common to all projects.Araxes
Hey, I've found in the docs what you want to do :D playframework.com/documentation/2.1.0/SBTSubProjectsTeteak
Trouble with sub-projects is that I can't store them in separate vcs roots, or it's too complicated. And I need to split them for sure(Araxes

© 2022 - 2024 — McMap. All rights reserved.