Skip to content

SrodriguezO/rules_play_routes

 
 

Repository files navigation

Play Framework Routes File Rules for Bazel

Build Status

Overview

rules_play_routes compiles Play Framework routes files templates to Scala, so they can be used with rules_scala.

For more information about the Play Framework, see the Play documentation.

Installation

Create a file called at the top of your repository named WORKSPACE and add the following snippet to it.

# update version as needed
rules_play_routes_version = "beca1e224c9f08813b55498da6db7f91721edea7"
http_archive(
  name = "io_bazel_rules_play_routes",
  sha256 = "bb37e52bf5bf2d11732b07e3baa1508b0cfdb9f8ce7645f346e215a954380a41",
  strip_prefix = "rules_play_routes-{}".format(rules_play_routes_version),
  type = "zip",
  url = "https://github.com/lucidsoftware/rules_play_routes/archive/{}.zip".format(rules_play_routes_version),
)

RULES_JVM_EXTERNAL_TAG = "2.1"
http_archive(
    name = "rules_jvm_external",
    sha256 = "515ee5265387b88e4547b34a57393d2bcb1101314bcc5360ec7a482792556f42",
    strip_prefix = "rules_jvm_external-{}".format(RULES_JVM_EXTERNAL_TAG),
    type = "zip",
    url = "https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(RULES_JVM_EXTERNAL_TAG),
)

load("@io_bazel_rules_play_routes//:workspace.bzl", "play_routes_repositories")
play_routes_repositories()

This installs rules_play_routes to your WORKSPACE at the specified commit. Update the commit as needed.

Stardoc Documentation

http://lucidsoftware.github.io/rules_play_routes/

Stardoc is replacing Skydoc and is currently under development. Doc is likely going to look funny for a while.

Updating Stardoc

Stardoc is automatically updated on build merged into the master branch. To update the documentation, please submit a pull request. The doc will be updated when it is merged.

Deploying documentation

The Stardoc site for rules_play_routes is deployed from the gh-pages branch. That branch is deployed with each build of the master branch.

Usage

The play_routes rule compiles Play routes files to a source jar that can be used with the rules_scala rules. For example,

play_routes(
  name = "play-routes",
  srcs = ["conf/routes"] + glob(["conf/*.routes"]),
  include_play_imports = True,
  generate_reverse_router = True,
  routes_imports = [...],
)

scala_binary(
  name = "foo-service",
  srcs = glob(["app/**/*.scala"]) + [":play-routes"],
  main_class = "foo.server.RunServer",
  deps = [...]
  )
)

See the Stardoc documentation for the full list of options for play_routes.

Use with the Play Framework

play_routes can be used with rules_twirl to run a Play Framework Service. For example

twirl_templates(
  name = "twirl-templates",
  source_directory = "app",
  include_play_imports = True,
  srcs = glob(["app/**/*.scala.html"])
    + glob(["app/**/*.scala.xml"])
    + glob(["app/**/*.scala.js"])
    + glob(["app/**/*.scala.txt"]),
  additional_imports = [...],
)

play_routes(
  name = "play-routes",
  srcs = ["conf/routes"] + glob(["conf/*.routes"]),
  include_play_imports = True,
  generate_reverse_router = True,
  routes_imports = [...],
)

scala_binary(
  name = "foo-service",
  srcs = glob(["app/**/*.scala"])  + [":twirl-templates", ":play-routes"],
  visibility = ["//visibility:public"],
  main_class = "play.core.server.ProdServerStart",
  resources = ["conf/logback.xml"] + glob(["conf/resources/**/*"]),
  resource_strip_prefix = native.package_name(),
  classpath_resources = ["conf/application.conf"],
  jvm_flags = [
  	"-Dhttp.port=9000",
  	"-Dapplication.name=foo-service",
  ],
  deps = [...],
)

Development

Command Line Play Routes Compiler

This project consists of the Play routes Bazel rules and a command line Play routes compiler compiler. The command line compiler can be built with

bazel build //play-routes-compiler

It can be run with

bazel run //play-routes-compiler

Testing

All tests can be run using

test/run_all_tests.sh

They can also be run using

bazel test //test/...

CI

The CI config in tools/bazel.rc and other options in .bazelrc.travis are used during CI builds.

Skylint

Skylint is run during CI builds. To run it locally use

tools/skylint.sh

About

Bazel rules for compiling Play Framework routes files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 58.5%
  • Scala 33.3%
  • Shell 8.2%