Which CI server works with SBT? - scala

I'm considering using SBT for a new scala project, but I'm not sure which CI server - hudson / cruise / whatever has support for it. Any ideas?
I know SBT is a little Maven like, but I don't think it can work as a drop in replacement for Maven in the eyes of a CI server.

By now you would have worked through this. But I found simple integration possible by getting Hudson to call a bash script that invoked SBT. I didn't do any further integration. The solution was able to trigger a build and show the output. That is all I needed at the time.

In my experience, Travis CI https://travis-ci.org works great with SBT. See http://about.travis-ci.org/docs/user/languages/scala/ for details on using them together.
Some of my own SBT-based projects on Travis:
https://travis-ci.org/SethTisue/lens-examples
https://travis-ci.org/NetLogo/NetLogo-Headless
https://travis-ci.org/NetLogo/Tortoise

Related

SBT/Scala and Integration testing

While researching on the subject of automating my integration tests, I found out a nice plugin in the maven world called FailSafe. it gives me phases like pre-integration-test, post-integration-test and integration-test.
By tying into these phases, I can have other plugins which can start/stop and run docker images.
The plugin also has a nice way in which I can differentiate between UnitTests and IntegrationTests (even though both are written in JUNIT).
Well now the question is how can I do the same thing with Scala / SBT combination?
my requirement is
Write Integration tests in SpecFlow.
Integration tests are treated differently than unit tests.
First Unit Tests are run.
Then docker containers are created and run
then integration tests are run.
docker contains are shut-down.
test results are captured in files. (just like surefire/failsafe plugins).
Is this possible in Scala/sbt combo?
A simple solution is to run $ sbt "~ it:test" (make sure integration test are in a package named 'it') for integration test which will automatically run every time source code is updated. Furthermore, $sbt "~ test" for automated unit testing. If you are using a IDE such as IntelliJ IDEA, you can make it easier to run this in a custom configuration from the IDE. Hope this helps a little bit. I run these all the time when working.
I found the answer to the question. SBT provides means to do integration test and also setup and cleanup methods to do things like creation / destruction of docker containers
http://www.scala-sbt.org/0.13/docs/Testing.html

How to debug/run a single gatling simulation in IntelliJ IDEA without sbt command?

How could I debug or run the BasicSimulation.scala?
Now I use sbt command to run:
testOnly simulations:BasicSimulation
Is there any other easy way to debug? Thanks.
You can add a simple class and run it by right click->run . Something like here: https://github.com/puppetlabs/gatling-puppet-load-test/blob/master/simulation-runner/src/main/scala/com/puppetlabs/gatling/runner/PuppetGatlingRunner.scala
If you want to run gatling tests inside the intellij, you can go to the edit configurations in the run toolbar on the top left and add a new sbt task.
On the task field enter testOnly simulations:BasicSimulation and that's it.
Normally you should be able to debug it by clicking the debug button, but it doesn't seems to be possible for the gatling tests at least in my configuration.
According to actual documentation this is done like:
gatling:testOnly *BasicSimulation*
Here the Documentation
As with any SBT testing framework, you’ll be able to run Gatling
simulations using SBT standard test, testOnly, testQuick, etc… tasks.
However, since the SBT Plugin introduces many customizations that we
don’t want interfering with unit tests, those commands are integrated
into custom configurations, meaning you’ll need to prefix them with
gatling or gatling-it, eg. gatling:test or gatling-it:test.
(I tested this in sbt console)
Everything is nicely explained in the official documentation page of the gatling project:
http://gatling.io/docs/2.2/extensions/maven_archetype/
Just use their archetype to generate a project in maven and then import in any decent IDE and voilà

How to use existing Intellij projects as a I move forward with SBT?

Novice SBT question - Now that I've started with some basic SBT tutorials, I'd like to start using SBT build files (within Intellij) a lot more often. However, there's a couple of problems with this :
1) Existing projects that I currently publish to a jar, and later import into other projects... how do I publish this jar file to my local repository? SBT publish-local doesn't seem to fit my situation, because the project was made in Intellij and is not (yet) an SBT project.
2) Suppose I do convert the project to an SBT build setup (and then import it into Intellij).. how do I configure Intellij to to publish-local (update) each time I build the project? I do not see many configurable settings around SBT within the new Intellij SBT support.
Using Intellij 13 and SBT 0.13.1
Thanks!
to get you started up quickly on using SBT to drive Idea, have a look at my template project called skeleton
It supports most of the basic tasks you'd want to do.
To publish to your repository, use the publish task.
hope that helps!
For publishing, you simply use the publish action:
To specify the repository, assign a repository to publishTo and optionally set the publishing style. For example, to upload to Nexus:
publishTo := Some("Sonatype Snapshots Nexus" at "https://oss.sonatype.org/content/repositories/snapshots")
As for your second question, despite being a JetBrains fanboy, I have found SBT integration quite disappointing. For one thing, as the JetBrains documentation states itself, you need two plugins: their plugin and sbt-idea. You use sbt-idea to synchronize the IDEA module structure with the SBT build, and you use JetBrains' idea-sbt-plugin to execute SBT tasks in the "Before Launch" action in Run Configurations.
It sounds like you want to do an "install" on every build, so "Before Launch" action support isn't useful. I would suggest writing your own custom SBT task to install on build and using the Command Line Tools Console to execute that task with SBT as if from the command line. I know; that indirection is annoying.
Bear in mind one more thing. I have found numerous bugs with idea-sbt-plugin. At least on Mac. JetBrains told me the next version will be much better, and you can see for yourself with the next EAP version.
I certainly welcome others who have managed to have more success than I have to chime in.

Is there a Sonar-level code coverage equivalent for Scala?

I'm trying to set up simple code coverage reports for a team coding in mixed Scala/Java at approx. a 90/10 ratio and running into some serious roadblocks. I've previously set up & administrated Sonar to great success with a Java-only team, but it doesn't appear to be an option.
Sonar w/Scala plugin is buggy and appears to support Scala-only projects, not mixed ones.
SCCT integrates with our maven build, but fails out with false-negative test failures repeatedly.
Undercover has been my best luck so far; It's integrated with our maven build & generates reports, but they aren't archived or hosted anywhere as they would be with Sonar. There also appears to be no central index to make it simple to navigate the generated reports.
I've read the answers here on StackOverflow, but they largely date back to 2010 and suggest that no decent solution is available. Has this changed?
Is there something obvious I'm missing?
About Sonar side:
yes, the Scala Sonar Plugin development is currently stalled. It was initiated by the community, but nobody has offered to take it over yet. If there are some volunteers, we'll be glad to guide and help them.
concerning the support of several languages inside a single project, support will be coming in Sonar. I can't give you a roadmap for it, but we're currently thinking about how to add this support in Sonar in the next releases, so this is a short term issue.
You can either use SCCT or JaCoCo.
SCCT: It supports Scala up to version 2.10, but development seems to be a stalled for a about 9 months. It supports Scala natively and works with both, Maven and SBT.
JaCoCo is under sctive development. It supports any version of Scala, but not natively, but on bytecode level. So you might get some artifacts, e.g. some code gets only partial coveragege, because the generated bytecode has some theoretical code path JaCoCo sees (but which can never be executed from Scala code).
JaCoCo can be a little tricky to set up with Maven and Scala. Here a few tricks:
Use the variant with the agent launcher. Do not use the variant with preprocessing bytecode.
When using JaCoCo with Maven: There is a Maven task (jacoco:prepare-agent) which will produce the correct expression for the agent launcher and stores it into a property. You can then use this property as a command line parameter when running the Java virtual machine.
Parametrize the agent launcher, so that multiple launches (e.g. for running different tests) write to the same log file. Some IDE plugins will have problems with parsing such a file, but the JaCoCo Hudson plugin for example works fine.

Deployment of Bndtools Projects in Hudson

Since I am a big fan of developing OSGi with Bndtools. I want to use it for my new project request as well. But one requirement is that all build processes should be done by Hudson.
My question is how I can achieve that I can use Hudson connected to my Bndtools projects? Maybe someone has a step-by-step tutorial for me :) Furthermore, will Hudson use OBR to resolve the dependencies like Bndtools is doing? How should such a deploy process look like? Btw Bndtools has its one "Integrated Test" project environment where it starts an OSGi environment in the background. Will Hudson understand such kind of tests?
What is best practice to use as much as possible of Bndtools?
Thanks for any help.
Christian
I found a way by just iterate with a custom main build.xml through each projects build.xml. I works and it's nothing special.
Create a new build task in hudson and define there ant build steps rather than introducing and maintaining a new build file.
Create for each project an ant build step.
In my case I created a task named BuildAll which has several ant build steps in it.