Last active
December 13, 2021 04:21
-
-
Save anton-fomin/807ca4614071585b2fbf63c76ebe0d87 to your computer and use it in GitHub Desktop.
How to run play framework with bloop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Should be put into ~/.sbt/1.0/plugins/bloop.sbt | |
// By default, this file does not do anything. | |
// If the environment variable BLOOP_ENABLED has the value 'true', | |
// then this file enables sbt-bloop. | |
if (System.getenv("BLOOP_ENABLED") == "true") { | |
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.3.4") | |
} else Nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
BLOOP_ENABLED=true sbt bloopInstall | |
# Bloop doesn't add web assets as a dependency, so when you run an app it doesn't have assets. | |
# You don't need this if you have app not serving any assets (some API) | |
# to keep things as they are already in bloop do not use pwd but read workspace from json | |
DIR=$(cat .bloop/root.json | jq -r '.project.directory') | |
WEB_ASSETS_DIR="$DIR/target/scala-2.12/*" | |
WEB_ASSETS_CLASSPATH_IDX=$(cat .bloop/root.json | jq -r '.project.classpath | index("'$WEB_ASSETS_DIR'")') | |
if [ "$WEB_ASSETS_CLASSPATH_IDX" = "null" ]; then | |
echo "$WEB_ASSETS_DIR is not in the classpath. It will be added" | |
cat .bloop/root.json | jq -r '.project.classpath += ["'$WEB_ASSETS_DIR'"]' > tmp.json && mv tmp.json .bloop/root.json | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
export _JAVA_OPTIONS="-Dconfig.file=conf/application.conf -Dhttps.port=9443" | |
# Here we listen for changes in scala files and files ending with web-assets.jar and restart the app | |
# plays web-assets:package task doesn't remove old webassets jars so we do this on restart | |
# with ls -t target/scala-2.12 | grep web-assets | tail -n+2 | xargs -I {} rm target/scala-2.12/{} | |
# as well as removing RUNNING_PID just in case | |
while true; do | |
fd --no-ignore "scala|web-assets.jar" -E "*scala.html" | entr -r -s "rm RUNNING_PID; ls -t target/scala-2.12 | grep web-assets | tail -n+2 | xargs -I {} rm target/scala-2.12/{}; bloop run root -m play.core.server.ProdServerStart" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# bloop will not compile web assets, routes and templates so we need to do this with sbt | |
sbt "~web-assets:package;twirlCompileTemplates;playRoutes" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment