26
Scala and Play with Gradle Wei Chen Sr. Software Engineer, Development Tools Gradle Summit 2015

Scala and Play with Gradle

Embed Size (px)

Citation preview

Page 1: Scala and Play with Gradle

Scala and Play with GradleWei Chen

Sr. Software Engineer, Development Tools

Gradle Summit 2015

Page 2: Scala and Play with Gradle

Build Happiness

Page 3: Scala and Play with Gradle

What this talk is about?

● Scala support in Gradle● Play support in Gradle● Continuous mode (watch mode)● Demos

Page 4: Scala and Play with Gradle

Who am I?

● A Software Engineer at Linkedin● Development Tools● Not a Scala expert● Not a Play expert● Maybe a build expert: make, ant, maven, sbt,

and gradle

Page 5: Scala and Play with Gradle

● Object oriented● Strong typed● Full support for functional programming● JVM based● 1.5% of LI code base (Java 25.1%)

Page 6: Scala and Play with Gradle

(Simple Build Tool? LOL)

● De facto build tool for scala community● Native support for compiling Scala code and

integrating with many Scala test frameworks● Build descriptions written in Scala using a DSL● Dependency management using Ivy● Continuous compilation, testing, and

deployment● Integration with the Scala interpreter for rapid

iteration and debugging● Support for mixed Java/Scala projects

Page 7: Scala and Play with Gradle

vs.

Sbt Gradle

DSL language Scala Groovy

Supported languages Scala, Java Java, Scala, C++, ...

Incremental Scala build Yes Possible with Zinc

Interactive Shell Yes No (but has Gradle daemon)

REPL Yes No

Multi-module support Yes Yes

Dependency Management Ivy proprietary

Continuous Mode Yes YES!

Vendor and community support Mediocre Great

Existing LI Tooling Integration Minimal when we started Great

Page 8: Scala and Play with Gradle

Scala Support in Gradle

● Scala plugin● From the very beginning of Gradle● 0.8 (September 2009)● Zinc support (1.3 November 2012)

Page 9: Scala and Play with Gradle

Demo

● Compiles Scala● Compiles Java● Joint compilation

Page 10: Scala and Play with Gradle

Limitations

● Scala version can only be inferred from direct dependencies

● No conflicting scala version validation● No cross-build support● No native specs2 integration● Bad IDE integration● Second class citizen in Scala world● Smaller adopter community

Page 11: Scala and Play with Gradle

Framework

● Web App Framework● Async I/O (JBoss Netty)● Built-in hot reloading● Built on top of sbt● Supports both Java and Scala● 159+ Play Applications

Page 12: Scala and Play with Gradle

Why to build Play on Gradle

● Pains with Ivy● Simplify our processes● Unify our build technologies● DRY

Page 13: Scala and Play with Gradle

Dependency Management

● Product catalog● Dependency validation● Repository management● Conflict resolution● Consistent versioning● Manifest generation/upload● Dependency resolution performance

Page 14: Scala and Play with Gradle

What’s involved?

1. Assets processing and packaging

2. Routes compilation

3. Twirl templates compilation

4. Scala/Java compilation

5. Running the server in development mode

6. Play binary packaging

7. Play distribution packaging

Page 15: Scala and Play with Gradle

Milestones

1. Using Gradle to build a Play application

2. Continuous Mode and Hot-Reload

3. Making it real!

Page 16: Scala and Play with Gradle

Demo

● Build a play app● Start the server in development mode

Page 17: Scala and Play with Gradle

Basic Sample Demo

● Apply play plugin● Declare dependencies● Configure repositories

Page 18: Scala and Play with Gradle

Advanced Sample Demo

● Apply CoffeeScript plugin● Configure target Scala and Play version

Page 19: Scala and Play with Gradle

Multiproject Sample Demo

● Standard Gradle multiproject build● “root” project: main Play application● 3 submodules:

○ admin: Play application○ user: Play application○ util: Java library

Page 20: Scala and Play with Gradle

Continuous Mode

● Gradle does not exit● Re-execute tasks when task file inputs

change● > Java 7 (file system WatchService)

Page 21: Scala and Play with Gradle

Demo

● gradle build● gradle test

Page 22: Scala and Play with Gradle

Play Hot Reload

● Stateless● Lightweight● Classloader magic● Used to be tightly coupled with build system

(sbt)● BuildLink

Page 23: Scala and Play with Gradle

Play Hot Reload

Page 24: Scala and Play with Gradle

Demo

Hot reload● Routes● Templates● Controller class

Page 25: Scala and Play with Gradle

Q & A

Thank you!Wei ChenSr. Software Engineer, Development Tools

[email protected]://www.linkedin.com/in/weichenlinkedin

Page 26: Scala and Play with Gradle

Useful Links

● https://docs.gradle.org/current/userguide/scala_plugin.html● https://github.com/gradle/gradle/blob/master/design-docs/play-support.

md● https://engineering.linkedin.com/play/developing-play-applications-

using-gradle● https://github.

com/playframework/playframework/blob/master/framework/src/build-link/src/main/java/play/core/BuildLink.java

● https://github.com/gradle/gradle● https://github.com/playframework/playframework