Skip to content

A Lagom sbt plugin for help developers to create new service in their project

Notifications You must be signed in to change notification settings

Fabszn/scaffolding-plugin-lagom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Purpose

The plugin is to ease the creation of new Lagom service nested in one lagom project.

Today, there is two ways for create a Lagom project.

First, start from scratch and create project by hand (create folder, create classes, files configuration, etc) or start from Lagom-java's project template activator. Second way makes things easier.

Ok but when your project has been generated by activator, you need to refactor the HelloWorld lagom service to give it the right name and right package name. Cool! now your project is ready to work. However, now, you need to create one (or more) service(s) then you start a copy/paste/rename party to create all new services.

Conclusion, you lose productivity while Lagom's framework should rise your productivity.

To fix this issue, I propose one plugin to generate entirely a new service by only one command :

sbt "newJavaService"

When this command is finished, you can apply runAll task to start your microservices system. Obviously, by default, your service will do nothing. But this plugin will bring you at the moment where you start design your API in Lagom interface.

Actually, service is generated with Java language.

How to setup the plugin

The plugin is available on the following repository :

http://bintray.com/fabszn/sbt-plugins

Fill the plugins.sbt file (under project directory by convention) with the following statements :

resolvers += Resolver.url("bintray.scaffolding-plugin.resolver", url("http://dl.bintray.com/fabszn/sbt-plugins"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.lightbend.lagom.sbt" %% "scaffolding-plugin-lagom" % "1.0.0-xx")

(where 'xx' corresponds to the latest version, check on the bintray repository)

Setting up is now finished. you should find new task named : newJavaService (and newScalaService)

How use the plugin

Using is very simple. at the sbt prompt use the following command :

> newJavaService [ServiceName]

org: parameter

By default, the plugin will used the organisation setting defined into the project. You can override it by used the parameter : org:

> newJavaService [ServiceName] org:xx.xx.xx

isTemplate: parameter

You needs to specify to the plugin if the initial project has been generated by template activator. For that, add the isTemplate parameter on the command line as follow :

new*Service myService isTemplate:true

(more details at the end of this page)

One more thing

Today, Lagom framework provided a Java API, however, with a trick, you can start to work with the Scala language. For that, the plugin provide another task that generate the service based on Scala language. Instead of used the task newJavaService, use the task newScalaService as described below:

> newScalaService [ServiceName]

Warning point /!\

This plugin has been design to work with a project that it is not created by the Lagom activator template. If your project has been initiated by the template activator, you will be faced with error into your build.sbt file.

Errors will be related with the manner to declare a module

((project in file(id))

Why this error?

The template activator adds, in the sbt build file, the following method:

def project(id: String) = Project(id, base = file(id))
  .settings(eclipseSettings: _*)
  .settings(javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8", "-Xlint:unchecked", "-Xlint:deprecation"))
  .settings(jacksonParameterNamesJavacSettings: _*) // applying it to every project even if not strictly needed.

It generate a conflict with the manner that plugin has generate the service declaration.

What can I do if my project has been created from activator.

if the initial project has been generate from the activator template, so on the command line add the parameter as below :

new*Service myService isTemplate:true

The plugin will make suitable the code to be compliant with.

That's all folks !

About

A Lagom sbt plugin for help developers to create new service in their project

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages