triggering more commands rather Play 'run' only - scala

When I try to run few commands with triggering in a Play project, say
~ ;run ;stage
, only run is triggering on source code changes. Is there a way to trigger both commands?
Play v.2.3.6 and sbt 0.13.7 are in use.

Try ~run.
I don't think you should use stage when doing development. stage is used to create folder (inside target/universal) that you can to package and run the app when you want to deploy it in test or production.

Related

How to auto-reload/hotswap with gradle and scala?

I have a Scala server application that uses gradle and scala and application plugins for build and running. I start the application with gradle run.
A part of my gradle. A typical one, really:
...
apply plugin: 'scala'
apply plugin: 'application'
...
mainClassName = "mypackage.Main"
How to automatically re-compile and restart the application whenever I modify the source code?
Preferably, using the CLI and gradle without any IDE usage. Also, I've heard a similar feature is in sbt, but I'm not intending to use sbt.
I think that you can use the --continous tag solution :
In a terminal:
gradle build --continuous
In an other terminal:
gradle run
I'd tried gradle run --continuous but didn't work because the run task is never-ending and seems like --continuous doesn't start a new build/task unless the previous one has finished.
So, the closest solution I could reach is:
Add an endpoint that shuts down the application.
Make a setup such that you can call the endpoint with one click.
Run gradle run --continuous.
If you make edits to the source code and want to restart the application, call the endpoint.
Yes, that's not exactly "automatically re-compiling and restarting" but that's the closest I could reach. Also, of course, don't keep needless endpoints in your code; either make it automatic to be unavailable in production, or don't apply this solution in the first place.

Executing tests in another build.gradle project

I am finishing a Continuous Integration system with Jenkins and Gradle for a REST service. It will build the App and dependent sub-libraries, build a Docker, start main docker and secondary ones (database, ...) all in Gradle.
As it is a REST service I have a separate project that executes the REST tests completely from outside my project just as it is a REST client, and works ok...
Once my project is built and everything running I need to execute the build in the other project (which is just for tests) as a subproject, and wether it passes or not the tests I want to continue the main script as Dockers need to be stopped and deleted. What is the best approach for this?
Thanks
You just need to create a task with type: GradleBuild in parameter
Example:
task buildAnotherProjectTask(type: GradleBuild) {
buildFile = '../pathToBuildFileInTheOtherProject/build.gradle'
tasks = ['build'] // You can run any task like that
tasks = ['test']
}
and to run it u can use the following command
gradle buildAnotherProjectTask
This is worked with me when i tried it.
Hope my answer will help :)

Having sbt to re-run on file changes - The `~ compile` equivalent for `run`

I know it's possible to re-compile or re-run tests on file changes. I want know to if it's possible to perform something similar for the run command. ~ run does not work. (That makes sense since the run never finishes).
Is there a way to create a task that watches for file changes, quit the running server and relaunch it ?
If not what other tool, would you suggest to get the same behaviour ?
You will have to bring in an external project like sbt-revolver
https://github.com/spray/sbt-revolver

End to end/integration testing - jenkins build

I am currently in a process of setting up Jenkins-CI for my Scala/Akka project.
I managed to create build that is integrated with BitBucket and executes builds when new pull reuqest is created/old pull request is updated.
As a testing framework we are using Specs2 which is also integrated with Jenkins by using JUnit post-build action. Now I am wondering how to properly execute e2e tests in my build.
Basically in git repository we have 2 projects, lets call them main-project and rest-tests. rest-tests contains e2e tests that are written using REST-assured library. To execute them I need to start main-project application (which uses Spray library to set up HTTP server) and then execute test task in sbt project of rest-test.
My idea was to execute main-project startup script (generated by sbt-native-packager) whith something like this:
$WORKSPACE/main-project/target/universal/stage/bin/main-project & echo $! > /tmp/main-project.pid
then execute test task of rest-tests project and finally kill process with PID that is saved in /tmp/main-project.pid file.
The last step should be implemented using https://wiki.jenkins-ci.org/display/JENKINS/Post+build+task because if some rest-testswill fail the next steps of build will not be executed (or at least that is what I am thinking) and I could end with my instance of application running after the build is finished.
This is first time when I am setting up CI system and my solution seems to be a little hacky (at least to me). I am wondering if there is a better/more idiomatic way of solving my problem of running e2e tests which require another application running.

Improving productivity with Scala test cycle

It would be great to improve test driven development productivity by automatically firing of tests whenever there is a code change.
This is what I'm hoping for.
Whenever a Scala file is saved, SBT (or a shell script) should execute the ScalaTest or Specs2 specifications.
If the tests complete, the system should play a sound indicating success or failure
I'm using Scala IDE to do development and SBT to run my test specs at the moment, so just autimating the steps above would save a person from switching to the console, running the test specs and waiting for the result.
Any ideas automatically firing of the tests and playing a 'succeed' or 'fail' sound would be great.
Why not create a custom SBT task that depends on the test task. You could add the code for playing the sound to your build definition.
See here how to run a custom task after another task.
To automatically re-run tests, simply prefix the newly define task with a ~ in the SBT shell before running it.