How to disable running tests in sbt publishLocal - scala

How do we disable running tests for sbt publishLocal ?
To disable running tests in assembly the following has been suggested (though I have seen it not working as well..):
sbt 'set test in assembly := {}' assembly
What about for publishLocal ? The following have all been attempted .. yet the tests always are run:
sbt 'set test in publish := {}' publishLocal
sbt 'set test in publishLocal := {}' publishLocal
sbt 'set test in assembly := {}' publishLocal

Related

How to run sbt assembly by excluding integration test

I am looking to create fat jar by 'sbt assembly' but i dont wan to run integration test in sbt assembly. I want only jar file.
You can either disable tests in your build.sbt using assembly / test := {} as suggested by #laughedelic, or if you're executing from a terminal and want to skip to the tests for that build use: sbt 'set test in assembly := {}' assembly.
If you have set the value in your build.sbt file you can check that its value is as expected by running sbt show assembly / test which should return something like ().

Excluding a src file from sbt compile?

I've been trying to exclude a file from "sbt run" and "sbt compile". The file is called SheetsQuickstart.java, and is in src/main/java. I'm using intelliJ's sbt shell to run these commands. (Perhaps it's not reading the build.sbt file?)
In build.sbt, I've tried lines like:
excludeFilter in (Compile, managedSources) := "SheetsQuickstart.java"
excludeFilter in managedSources := "SheetsQuickstart.java"
excludeFilter in unmanagedSources := "SheetsQuickstart.java"
excludeFilter in managedSources := "SheetsQuickstart.class"
excludeFilter in managedSources := "*.java" `
I still get compilation errors in SheetsQuickstart.java when I compile using sbt, despite having tried to exclude it.

SBT dependsOn usage - migration from 0.12 to 0.13

I have a command like this in build.sbt
run <<= (run in Compile) dependsOn npmBuildTask
According to documentation <<= is deprecated so I want to use := this one.
I tried with;
run in Compile := ((run in Compile).dependsOn(npmBuildTask).value)
run in Compile := (run in Compile).dependsOn(npmBuildTask).value
run in Compile := run.dependsOn(npmBuildTask).value
But whole of them are not working for me. Could you please help me?
Finally I found the solution.
compile := ((compile in Compile) dependsOn npmBuildTask).value
This is working for me. The problem was in the following code:
run := ((run in Compile) dependsOn npmBuildTask).value
compile and run are different. compile has a return type as sbt.TaskKey[sbt.inc.Analysis] and run has a return type as sbt.InputKey[scala.Unit]. Because of this you should use this command:
run := ((run in Compile) dependsOn npmBuildTask).evaluated
Now everything is working fine.

Send module version as command line argument to SBT

I am using TeamCity to run a bash script that is utilizing SBT Native Packager to publish an image to Docker. The sbt portion of the bash script looks something like this:
sbt -DdockerRepository=$repo -DpackageName=$packageName -D myproject/docker:publish
I want to pass on the TeamCity build number as a version number to my package. Today I specify the version number manually in settings in build.sbt:
settings(
version := "0.20",
....,
dockerBaseImage := "example.com:5000/linux/java8:latest",
dockerRepository in Docker := Some("example.com/myoldrepo"),
dockerUpdateLatest := true'
)
I want to be able to do it like this:
activator -Dversion=0.21 -DpackageName=myproject -D myproject/docker:publish
but this does not seem to work. Yet overriding the dockerRepository like I do above is working.
How can I pass my desired version number into SBT from the command line/TeamCity?
You could set version before publish:
sbt 'set version := "1.0"' docker:publish
Try something like this:
val myVersion = util.Properties.propOrNone("version").getOrElse("0.20")
val myDockerBaseImage = util.Properties.propOrNone("dockerBaseImage").
getOrElse("example.com:5000/linux/java8:latest")
lazy val myProject = Project("myProject",file("path")).settings(
version := myVersion,
dockerBaseImage := myDockerBaseImage,
....,
dockerRepository in Docker := Some("example.com/myoldrepo"),
dockerUpdateLatest := true
)
And then call it (depends on your sbt installation):
SBT_OPTS="-Dversion=0.21" sbt
sbt -Dversion=0.21
activator -Dversion=0.21

Compile tests with SBT and package them to be run later

Im working with SBT and Play! Framework. Currently we have a commit stage in our pipeline where we publish to artifactory our binaries. The binaries are generated with the dist task. The pipeline then runs smoke and acceptance tests that are written in scala. They are run with sbt.
What I want to do is to compile the smoke and acceptance tests as well as the binary and publish them to artifactory. That will allow the pipeline to download these binaries (the test suites) and run them, instead of recompiling them every time, which takes a long time.
I tried sbt test:compile which generates the jar, but then I cant find a way to run the tests.
sbt dont publish test in artifacts
publishArtifact in GlobalScope in Test:== false
source: https://github.com/sbt/sbt/blob/a7413f6415687f32e6365598680f3bb8545c46b5/main/src/main/scala/sbt/Defaults.scala#L1118
this is how to enable it
// enable publishing the jar produced by `test:package`
publishArtifact in (Test, packageBin) := true
// enable publishing the test API jar
publishArtifact in (Test, packageDoc) := true
// enable publishing the test sources jar
publishArtifact in (Test, packageSrc) := true
source: http://www.scala-sbt.org/release/docs/Detailed-Topics/Artifacts
run the test
scala -classpath pipeline.jar classpath scalatest-<version>.jar org.scalatest.tools.Runner -p compiled_tests
where pipeline.jar is the test artifact you receive from the pipeline
or you can setup a test projet via sbt
http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing.html