Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 282
YoZH Avatar asked Jun 28 '15 18:06

YoZH


People also ask

Which component is responsible for building play framework?

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java.

What is action in play framework?

What is an Action? Most of the requests received by a Play application are handled by an action. An action is basically a Java method that processes the request parameters, and produces a result to be sent to the client. public Result index(Http. Request request) { return ok("Got request " + request + "!"

Why play framework is used?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

What is MVC in play framework?

A play application follows the MVC architectural pattern applied to the Web architecture. This pattern splits the application into separate layers: the Presentation layer and the Model layer. The Presentation layer is further split into a View and a Controller layer.


1 Answers

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.

like image 87
Augusto Avatar answered Oct 11 '22 22:10

Augusto