简体   繁体   中英

Play Framework project composition

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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