Scaffolding-plugin for Lagom - The Reactive Microservices Framework
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.
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)
Using is very simple. at the sbt prompt use the following command :
> newJavaService [ServiceName]
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
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)
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]
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))
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.
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 !