Skip to content

Commit

Permalink
Gradle support for play-scala-rest-api-example
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage committed Dec 13, 2023
1 parent 872a0b3 commit d312f04
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 3 deletions.
9 changes: 9 additions & 0 deletions play-scala-rest-api-example/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions play-scala-rest-api-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
28 changes: 27 additions & 1 deletion play-scala-rest-api-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This is the example project for making a REST API in Play.

### Running

#### Running (Sbt)

You need to download and install sbt for this application to run.

Once you have sbt installed, the following at the command prompt will start up Play in development mode:
Expand All @@ -14,6 +16,16 @@ Once you have sbt installed, the following at the command prompt will start up P
sbt run
```

#### Running (Gradle)

The following at the command prompt will start up Play in development mode:

```bash
./gradlew playRun
```

#### Hot-reload

Play will start up on the HTTP port at <http://localhost:9000/>. You don't need to deploy or reload anything -- changing any source code while the server is running will automatically recompile and hot-reload the application on the next HTTP request.

### Usage
Expand Down Expand Up @@ -46,6 +58,8 @@ POST /v1/posts HTTP/1.1

The best way to see what Play can do is to run a load test. We've included Gatling in this test project for integrated load testing.

#### Play in production mode (Sbt)

Start Play in production mode, by [staging the application](https://www.playframework.com/documentation/latest/Deploying) and running the play scripts:

```bash
Expand All @@ -54,6 +68,18 @@ cd target/universal/stage
./bin/play-scala-rest-api-example -Dplay.http.secret.key=some-long-key-that-will-be-used-by-your-application
```

### Play in production mode (Gradle)

Start Play in production mode, by [building a distribution](https://docs.gradle.org/current/userguide/application_plugin.html#sec:the_distribution) and running the next script

```bash
./gradlew installDist
cd build/install/play-scala-rest-api-example
JAVA_OPTS="-Dplay.http.secret.key=some-long-key-that-will-be-used-by-your-application" ./bin/play-scala-rest-api-example
```

#### Gatling

Then you'll start the Gatling load test up (it's already integrated into the project):

```bash
Expand All @@ -65,7 +91,7 @@ For best results, start the gatling load test up on another machine so you do no
Once the test completes, you'll see an HTML file containing the load test chart:

```bash
./play-scala-rest-api-example/target/gatling/gatlingspec-1472579540405/index.html
./play-scala-rest-api-example/gatling/target/gatling/gatlingspec-1472579540405/index.html
```

That will contain your load test results.
48 changes: 48 additions & 0 deletions play-scala-rest-api-example/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import play.gradle.Language
import play.gradle.plugin.PlayPlugin

plugins {
alias(libs.plugins.twirl)
alias(libs.plugins.play)
}

play {
lang = Language.SCALA
}

def scalaVersion = System.getProperty('scala.version', PlayPlugin.DEFAULT_SCALA_VERSION).replaceAll('\\D*$', '')

dependencies {
implementation platform("org.playframework:play-bom_${scalaVersion}:${libs.versions.play.get()}")

implementation "org.playframework:play-pekko-http-server_${scalaVersion}"
implementation "org.playframework:play-guice_${scalaVersion}"
implementation "org.playframework:play-logback_${scalaVersion}"
implementation "net.codingwell:scala-guice_${scalaVersion}:${libs.versions.scala.guice.get()}"
implementation "io.lemonlabs:scala-uri_${scalaVersion}:${libs.versions.scala.uri.get()}"
implementation libs.logstash.logback.encoder

testImplementation "org.playframework:play-test_${scalaVersion}"
testImplementation "org.playframework:play-filters-helpers_${scalaVersion}"
testImplementation "org.scalatestplus.play:scalatestplus-play_${scalaVersion}:${libs.versions.scalatestplus.play.get()}"
testImplementation libs.scalatest.junit.runner
}

run {
systemProperties System.properties
}

test {
useJUnitPlatform {
includeEngines 'scalatest'
}
}

// TODO: Remove after release Play Gradle Plugin
repositories {
mavenCentral()
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
mavenLocal()
}
1 change: 0 additions & 1 deletion play-scala-rest-api-example/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ lazy val root = (project in file("."))
crossScalaVersions := Seq(scala213, scala3),
libraryDependencies ++= Seq(
guice,
"org.joda" % "joda-convert" % "2.2.3",
"net.logstash.logback" % "logstash-logback-encoder" % "7.3",
"io.lemonlabs" %% "scala-uri" % "4.0.3",
"net.codingwell" %% "scala-guice" % "6.0.0",
Expand Down
17 changes: 17 additions & 0 deletions play-scala-rest-api-example/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[versions]
twirl = "2.0.3"
play = "3.0.1-03969c1e-SNAPSHOT"
scala-guice = "6.0.0"
scala-uri = "4.0.3"
scalatestplus-play = "7.0.0"

[libraries]
logstash-logback-encoder = { group = "net.logstash.logback", name = "logstash-logback-encoder", version = "7.3" }
scalatest-junit-runner = { group = "co.helmethair", name = "scalatest-junit-runner", version = "0.1.12" }
scala-guice = { group = "net.codingwell", name = "scala-guice_2.13", version.ref = "scala-guice" }
scala-uri = { group = "io.lemonlabs", name = "scala-uri_2.13", version.ref = "scala-uri" }
scalatestplus-play = { group = "org.scalatestplus.play", name = "scalatestplus-play_2.13", version.ref = "scalatestplus-play" }

[plugins]
twirl = { id = "org.playframework.twirl", version.ref = "twirl" }
play = { id = "org.playframework.play", version.ref = "play" }
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit d312f04

Please sign in to comment.