Tips and tricks for setting up a Play 2 project

Manuel Bernhardt
Manuel BernhardtReactive Systems Consultant at manuel.bernhardt.io
Tips and tricks for setting up a
Play 2 project
!
!

Manuel Bernhardt

#DV13PlayTricks

@elmanu
play new hello-play
Let’s get started

#DV13PlayTricks

@elmanu
Hello world - build.sbt
name := "hello-play"!
!

version := "1.0-SNAPSHOT"!
!

libraryDependencies ++= Seq(!
jdbc,!
anorm,!
cache!
)
!
!

play.Project.playScalaSettings!

#DV13PlayTricks

@elmanu
Hello world - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!

// The Typesafe repository !
resolvers += "Typesafe repository" at "http://
repo.typesafe.com/typesafe/releases/"!
!

// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")!

#DV13PlayTricks

@elmanu
First things first: Scalariform
!

Code indentation is good for your health

#DV13PlayTricks

@elmanu
Scalariform! - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!

// The Typesafe repository !
resolvers += "Typesafe repository" at "http://
repo.typesafe.com/typesafe/releases/"!
!

// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")!
!

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")!

#DV13PlayTricks

@elmanu
Scalariform! - build.sbt
name := "hello-play"!
!

version := "1.0-SNAPSHOT"!
!

libraryDependencies ++= Seq(cache)!
!

play.Project.playScalaSettings!
!

scalariformSettings

#DV13PlayTricks

@elmanu
#DV13PlayTricks

@elmanu
#DV13PlayTricks

@elmanu
Scalastyle
Keep it clean

#DV13PlayTricks

@elmanu
Scalastyle! - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!

// The Typesafe repository !
resolvers += "Typesafe repository" at "http://
repo.typesafe.com/typesafe/releases/"!
!

// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")!
!

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")!
!

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" %
"0.3.2")

#DV13PlayTricks

@elmanu
Scalastyle! - build.sbt
name := "hello-play"!
!

version := "1.0-SNAPSHOT"!
!

libraryDependencies ++= Seq(cache)!
!

play.Project.playScalaSettings!
!

scalariformSettings!
!

org.scalastyle.sbt.ScalastylePlugin.Settings

#DV13PlayTricks

@elmanu
Scalastyle! - scalastyle-config.xml
<scalastyle>!
<name>Scalastyle sample configuration</name>!
<check level=“warning”!
class=“org.scalastyle.file.FileLineLengthChecker"!
enabled="true">!
<parameters>!
<parameter name="maxLineLength"><![CDATA[100]]></parameter>!
<parameter name="tabSize"><![CDATA[2]]></parameter>!
</parameters>!
</check>!
</scalastyle>

#DV13PlayTricks

@elmanu
Scalastyle! - Output
<?xml version="1.0" encoding="US-ASCII"?>!
<checkstyle version=“5.0”>!
<file name=“/Users/manu/w/hello-play/app/controllers/Application.scala">!
<error line=“12"!
source=“org.scalastyle.file.FileLineLengthChecker"!
severity=“warning"!
message="File line length exceeds 100 characters”>!
</error>!
</file>!
</checkstyle>!

#DV13PlayTricks

@elmanu
Sub-projects
!

Keeping things fast

#DV13PlayTricks

@elmanu
Root

Module 1

Module 2

Core

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
#DV13PlayTricks

@elmanu
application.conf

#DV13PlayTricks

@elmanu
routes

application.conf

module1.routes

module2.routes

#DV13PlayTricks

@elmanu
Snapshot dependencies and
multi-module projects
Workarounds

#DV13PlayTricks

@elmanu
Snapshot dependencies

• https://github.com/sbt/sbt/issues/413

#DV13PlayTricks

@elmanu
Snapshot dependencies

• https://github.com/sbt/sbt/issues/413

#DV13PlayTricks

@elmanu
Snapshot dependencies - workarounds

• Don’t use snapshot dependencies	

• Convince library authors to make releases	

• Use a cache, e.g. Squid	

•

OS X: http://squidman.net/squidman

-­‐Dhttp.proxyHost=localhost	
  -­‐Dhttp.proxyPort=8090

#DV13PlayTricks

@elmanu
Tools for Chrome
After all, we’re building web-applications

#DV13PlayTricks

@elmanu
https://chrome.google.com/webstore/detail/play-framework-tools/dchhggpgbommpcjpogaploblnpldbmen

#DV13PlayTricks

@elmanu
Play Auto Refresh - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!
// The Typesafe repository !
resolvers += "Typesafe repository" at "http://repo.typesafe.com/
typesafe/releases/"!
!
// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")!
!
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")!
!
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2")!
!
addSbtPlugin("com.jamesward" %% "play-auto-refresh" % "0.0.7")

#DV13PlayTricks

@elmanu
Play Auto Refresh - build.sbt
name := "hello-play"!
!
version := "1.0-SNAPSHOT"!
!
libraryDependencies ++= Seq(!
jdbc,!
anorm,!
cache!
)
!
!
play.Project.playScalaSettings!
!
scalariformSettings!
!
org.scalastyle.sbt.ScalastylePlugin.Settings!
!
com.jamesward.play.BrowserNotifierPlugin.livereload

#DV13PlayTricks

@elmanu
Chrome

Your IDE

play ~ run
No more ⌘+R, yeah!
#DV13PlayTricks

@elmanu
Open errors in IDE

Click to open in editor

Instructions at https://github.com/jamesward/play-framework-chrome-tools
#DV13PlayTricks

@elmanu
Use dependency injection right
away
A poor man’s solution

#DV13PlayTricks

@elmanu
DI - Users controller
package controllers!
!

class Users(greeting: String) extends BaseController {!
!

def hello = Action { implicit request =>!
! Ok(greeting)!
}!
!

}

#DV13PlayTricks

@elmanu
DI - Routes

GET

#DV13PlayTricks

/users

@controllers.Users.hello!

@elmanu
DI - Global.scala
import controllers.Users!
import play.api.GlobalSettings!
!
object Global extends GlobalSettings {!
!
override def getControllerInstance[A](controllerClass: Class[A]): A = {!
!
val USERS = classOf[Users]!
!
val instance = controllerClass match {!
case USERS => new Users("Hello users")!
case _ => super.getControllerInstance(controllerClass)!
}!
!
instance.asInstanceOf[A]!
}!
}

#DV13PlayTricks

@elmanu
That’s it! Questions?
!
https://github.com/manuelbernhardt/hello-play-dv13
!
http://manuel.bernhardt.io

#DV13PlayTricks

@elmanu
1 of 39

Recommended

The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving... by
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...Puppet
1.7K views13 slides
Puppet modules for Fun and Profit by
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and ProfitAlessandro Franceschi
3.7K views24 slides
Massive device deployment - EclipseCon 2011 by
Massive device deployment - EclipseCon 2011Massive device deployment - EclipseCon 2011
Massive device deployment - EclipseCon 2011Angelo van der Sijpt
3K views48 slides
Device deployment by
Device deploymentDevice deployment
Device deploymentAngelo van der Sijpt
3.6K views77 slides
Java 8 Puzzlers as it was presented at Codemash 2017 by
Java 8 Puzzlers as it was presented at Codemash 2017Java 8 Puzzlers as it was presented at Codemash 2017
Java 8 Puzzlers as it was presented at Codemash 2017Baruch Sadogursky
660 views78 slides
Evolving systems and the link to service orientation by
Evolving systems and the link to service orientationEvolving systems and the link to service orientation
Evolving systems and the link to service orientationAngelo van der Sijpt
518 views51 slides

More Related Content

What's hot

Introduction To Django (Strange Loop 2011) by
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Jacob Kaplan-Moss
14.4K views139 slides
RabbitMQ by
RabbitMQRabbitMQ
RabbitMQvoluntas
1.7K views26 slides
Theme Development and Customization by
Theme Development and CustomizationTheme Development and Customization
Theme Development and CustomizationAniket Pant
2.5K views30 slides
Getting Started With Play Framework by
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play FrameworkTreasury user10
152 views7 slides
HTML5: Building for a Faster Web by
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster WebEric Bidelman
4.1K views52 slides
Puppet for Everybody: Federated and Hierarchical Puppet Enterprise by
Puppet for Everybody: Federated and Hierarchical Puppet EnterprisePuppet for Everybody: Federated and Hierarchical Puppet Enterprise
Puppet for Everybody: Federated and Hierarchical Puppet EnterprisecbowlesUT
582 views46 slides

What's hot(6)

Introduction To Django (Strange Loop 2011) by Jacob Kaplan-Moss
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss14.4K views
RabbitMQ by voluntas
RabbitMQRabbitMQ
RabbitMQ
voluntas1.7K views
Theme Development and Customization by Aniket Pant
Theme Development and CustomizationTheme Development and Customization
Theme Development and Customization
Aniket Pant2.5K views
Getting Started With Play Framework by Treasury user10
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play Framework
Treasury user10152 views
HTML5: Building for a Faster Web by Eric Bidelman
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster Web
Eric Bidelman4.1K views
Puppet for Everybody: Federated and Hierarchical Puppet Enterprise by cbowlesUT
Puppet for Everybody: Federated and Hierarchical Puppet EnterprisePuppet for Everybody: Federated and Hierarchical Puppet Enterprise
Puppet for Everybody: Federated and Hierarchical Puppet Enterprise
cbowlesUT582 views

Similar to Tips and tricks for setting up a Play 2 project

Play vs Rails by
Play vs RailsPlay vs Rails
Play vs RailsDaniel Cukier
45.7K views36 slides
Buildr In Action @devoxx france 2012 by
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
2.4K views68 slides
Iphone and Ipad development Game with Cocos2D by
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2Dcreagamers
1.8K views47 slides
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet by
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, PuppetPuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, PuppetPuppet
868 views31 slides
Sbt, idea and eclipse by
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
1.4K views20 slides
Phing by
PhingPhing
Phingmdekrijger
3K views15 slides

Similar to Tips and tricks for setting up a Play 2 project(20)

Buildr In Action @devoxx france 2012 by alexismidon
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
alexismidon2.4K views
Iphone and Ipad development Game with Cocos2D by creagamers
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2D
creagamers1.8K views
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet by Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, PuppetPuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
Puppet868 views
Sbt, idea and eclipse by Mike Slinn
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
Mike Slinn1.4K views
Creating Better Builds with Gradle by Andres Almiray
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
Andres Almiray239 views
Summit2014 topic 0153 - Alfresco Maven for shared properties by Angel Borroy López
Summit2014 topic 0153 - Alfresco Maven for shared propertiesSummit2014 topic 0153 - Alfresco Maven for shared properties
Summit2014 topic 0153 - Alfresco Maven for shared properties
"I have a framework idea" - Repeat less, share more. by Fabio Milano
"I have a framework idea" - Repeat less, share more."I have a framework idea" - Repeat less, share more.
"I have a framework idea" - Repeat less, share more.
Fabio Milano1.3K views
Composer: putting dependencies on the score by Rafael Dohms
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the score
Rafael Dohms20.8K views
Advanced Topics in Continuous Deployment by Mike Brittain
Advanced Topics in Continuous DeploymentAdvanced Topics in Continuous Deployment
Advanced Topics in Continuous Deployment
Mike Brittain8.4K views
Forget Grunt and Gulp! Webpack and NPM rule them all! by Derek Willian Stavis
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
How to start using Scala by Ngoc Dao
How to start using ScalaHow to start using Scala
How to start using Scala
Ngoc Dao2.2K views
Eight Rules for Making Your First Great Game by Nick Pruehs
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great Game
Nick Pruehs485 views
Acceptance testing plone sites and add ons with robot framework and selenium by Asko Soukka
Acceptance testing plone sites and add ons with robot framework and seleniumAcceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and selenium
Asko Soukka23.5K views
IzPack at LyonJUG'11 by julien.ponge
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11
julien.ponge1.4K views
Publishing a Perl6 Module by ast_j
Publishing a Perl6 ModulePublishing a Perl6 Module
Publishing a Perl6 Module
ast_j1.5K views
A Recovering Java Developer Learns to Go by Matt Stine
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
Matt Stine13.8K views

More from Manuel Bernhardt

Is there anybody out there? Reactive Systems Hamburg by
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgManuel Bernhardt
339 views75 slides
Is there anybody out there? Scala Days Berlin 2018 by
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Manuel Bernhardt
427 views74 slides
Is there anybody out there? by
Is there anybody out there?Is there anybody out there?
Is there anybody out there?Manuel Bernhardt
340 views62 slides
Is there anybody out there? by
Is there anybody out there?Is there anybody out there?
Is there anybody out there?Manuel Bernhardt
447 views67 slides
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017 by
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 20178 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017Manuel Bernhardt
1.2K views69 slides
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of by
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware ofScala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware ofManuel Bernhardt
3.6K views67 slides

More from Manuel Bernhardt(19)

Is there anybody out there? Reactive Systems Hamburg by Manuel Bernhardt
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems Hamburg
Manuel Bernhardt339 views
Is there anybody out there? Scala Days Berlin 2018 by Manuel Bernhardt
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018
Manuel Bernhardt427 views
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017 by Manuel Bernhardt
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 20178 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
Manuel Bernhardt1.2K views
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of by Manuel Bernhardt
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware ofScala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Manuel Bernhardt3.6K views
8 Akka anti-patterns you'd better be aware of by Manuel Bernhardt
8 Akka anti-patterns you'd better be aware of8 Akka anti-patterns you'd better be aware of
8 Akka anti-patterns you'd better be aware of
Manuel Bernhardt4.4K views
Beyond the buzzword: a reactive web-appliction in practice by Manuel Bernhardt
Beyond the buzzword: a reactive web-appliction in practiceBeyond the buzzword: a reactive web-appliction in practice
Beyond the buzzword: a reactive web-appliction in practice
Manuel Bernhardt613 views
Beyond the Buzzword - a reactive application in practice by Manuel Bernhardt
Beyond the Buzzword - a reactive application in practiceBeyond the Buzzword - a reactive application in practice
Beyond the Buzzword - a reactive application in practice
Manuel Bernhardt492 views
3 things you must know to think reactive - Geecon Kraków 2015 by Manuel Bernhardt
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
Manuel Bernhardt4.2K views
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM by Manuel Bernhardt
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Manuel Bernhardt1.4K views
Back to the futures, actors and pipes: using Akka for large-scale data migration by Manuel Bernhardt
Back to the futures, actors and pipes: using Akka for large-scale data migrationBack to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
Manuel Bernhardt13K views
Project Phoenix - From PHP to the Play Framework in 3 months by Manuel Bernhardt
Project Phoenix - From PHP to the Play Framework in 3 monthsProject Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 months
Manuel Bernhardt2.6K views

Recently uploaded

Kyo - Functional Scala 2023.pdf by
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfFlavio W. Brasil
418 views92 slides
The Forbidden VPN Secrets.pdf by
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdfMariam Shaba
20 views72 slides
STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
14 views1 slide
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
48 views69 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
58 views21 slides
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
27 views49 slides

Recently uploaded(20)

The Forbidden VPN Secrets.pdf by Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker48 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software317 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson126 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays24 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive

Tips and tricks for setting up a Play 2 project

  • 1. Tips and tricks for setting up a Play 2 project ! ! Manuel Bernhardt #DV13PlayTricks @elmanu
  • 2. play new hello-play Let’s get started #DV13PlayTricks @elmanu
  • 3. Hello world - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(! jdbc,! anorm,! cache! ) ! ! play.Project.playScalaSettings! #DV13PlayTricks @elmanu
  • 4. Hello world - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http:// repo.typesafe.com/typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")! #DV13PlayTricks @elmanu
  • 5. First things first: Scalariform ! Code indentation is good for your health #DV13PlayTricks @elmanu
  • 6. Scalariform! - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http:// repo.typesafe.com/typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")! ! addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")! #DV13PlayTricks @elmanu
  • 7. Scalariform! - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(cache)! ! play.Project.playScalaSettings! ! scalariformSettings #DV13PlayTricks @elmanu
  • 11. Scalastyle! - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http:// repo.typesafe.com/typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")! ! addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")! ! addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2") #DV13PlayTricks @elmanu
  • 12. Scalastyle! - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(cache)! ! play.Project.playScalaSettings! ! scalariformSettings! ! org.scalastyle.sbt.ScalastylePlugin.Settings #DV13PlayTricks @elmanu
  • 13. Scalastyle! - scalastyle-config.xml <scalastyle>! <name>Scalastyle sample configuration</name>! <check level=“warning”! class=“org.scalastyle.file.FileLineLengthChecker"! enabled="true">! <parameters>! <parameter name="maxLineLength"><![CDATA[100]]></parameter>! <parameter name="tabSize"><![CDATA[2]]></parameter>! </parameters>! </check>! </scalastyle> #DV13PlayTricks @elmanu
  • 14. Scalastyle! - Output <?xml version="1.0" encoding="US-ASCII"?>! <checkstyle version=“5.0”>! <file name=“/Users/manu/w/hello-play/app/controllers/Application.scala">! <error line=“12"! source=“org.scalastyle.file.FileLineLengthChecker"! severity=“warning"! message="File line length exceeds 100 characters”>! </error>! </file>! </checkstyle>! #DV13PlayTricks @elmanu
  • 17. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 18. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 19. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 20. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 21. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 25. Snapshot dependencies and multi-module projects Workarounds #DV13PlayTricks @elmanu
  • 28. Snapshot dependencies - workarounds • Don’t use snapshot dependencies • Convince library authors to make releases • Use a cache, e.g. Squid • OS X: http://squidman.net/squidman -­‐Dhttp.proxyHost=localhost  -­‐Dhttp.proxyPort=8090 #DV13PlayTricks @elmanu
  • 29. Tools for Chrome After all, we’re building web-applications #DV13PlayTricks @elmanu
  • 31. Play Auto Refresh - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http://repo.typesafe.com/ typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")! ! addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")! ! addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2")! ! addSbtPlugin("com.jamesward" %% "play-auto-refresh" % "0.0.7") #DV13PlayTricks @elmanu
  • 32. Play Auto Refresh - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(! jdbc,! anorm,! cache! ) ! ! play.Project.playScalaSettings! ! scalariformSettings! ! org.scalastyle.sbt.ScalastylePlugin.Settings! ! com.jamesward.play.BrowserNotifierPlugin.livereload #DV13PlayTricks @elmanu
  • 33. Chrome Your IDE play ~ run No more ⌘+R, yeah! #DV13PlayTricks @elmanu
  • 34. Open errors in IDE Click to open in editor Instructions at https://github.com/jamesward/play-framework-chrome-tools #DV13PlayTricks @elmanu
  • 35. Use dependency injection right away A poor man’s solution #DV13PlayTricks @elmanu
  • 36. DI - Users controller package controllers! ! class Users(greeting: String) extends BaseController {! ! def hello = Action { implicit request =>! ! Ok(greeting)! }! ! } #DV13PlayTricks @elmanu
  • 38. DI - Global.scala import controllers.Users! import play.api.GlobalSettings! ! object Global extends GlobalSettings {! ! override def getControllerInstance[A](controllerClass: Class[A]): A = {! ! val USERS = classOf[Users]! ! val instance = controllerClass match {! case USERS => new Users("Hello users")! case _ => super.getControllerInstance(controllerClass)! }! ! instance.asInstanceOf[A]! }! } #DV13PlayTricks @elmanu