The scalastyle configuration in build.sbt is set as follows:
(scalastyleConfig in Test) := baseDirectory.value / "scalastyle-config.xml"
(scalastyleConfig in IntegrationTest) := baseDirectory.value / "scalastyle-config.xml"
Nevertheless, the sbt "it:scalastyle" does not check the source files in the /src/it directory. This command just ignores the it and checks the sources in the /src/main directory.
sbt "test:scalastyle" works fine.
Any idea on how I can fix this issue?
Update: After I remove the configurations in the build.sbt, I am still able to use test:scalastyle but not it:scalastyle.
Assuming you use lazy val IntegrationTest= config("it") extend Test to define it
,then you can use the following code which just modified from the plugin's source code.
Project.inConfig(IntegrationTest)(rawScalastyleSettings())
(scalastyleConfig in IntegrationTest) := (scalastyleConfig in Test).value
(scalastyleConfigUrl in IntegrationTest) := None
(scalastyleConfigRefreshHours in IntegrationTest) := (scalastyleConfigRefreshHours in Test).value
(scalastyleTarget in IntegrationTest) := target.value / "scalastyle-it-result.xml"
(scalastyleFailOnError in IntegrationTest) := (scalastyleFailOnError in Test).value
(scalastyleSources in IntegrationTest) := Seq((scalaSource in IntegrationTest).value)
Relevant Github issue: Github issue: https://github.com/scalastyle/scalastyle-sbt-plugin/issues/64
Related
I would like to have a different version of library in test scope.
I was hoping the simplified version of project descriptor could look like that.
Please mind it's a simplified view, in my real project it's more convoluted. I need to use dependencyOverrides to enforce certain library version.
import sbt._, Keys._
organization := "me"
name := "test"
version := "0.1"
libraryDependencies := Seq("ch.qos.logback" % "logback-classic" % "1.2.3")
dependencyOverrides := Seq(
"ch.qos.logback" % "logback-classic" % "1.2.2"
)
dependencyOverrides in Test := Seq(
"ch.qos.logback" % "logback-classic" % "1.2.1"
)
I'd be hoping to see logback-classic version 1.2.1 when I run:
show test:managedClasspath.
Instead I get logback-classic version 1.2.2 as if dependencyOverrides in Test was ignored.
At the same time when I run show Test/dependencyOverrides I get the expected result which is:
ch.qos.logback:logback-classic:1.2.1
Does anyone has a clue what am I missing in the relation between dependencyOverrides in Test scope and managedClasspath?
It appears the problem cannot be solve the way I imagined. The main reason is libraryDependencies and update are not scoped to configuration.
I think the best solution is in case I need a different version of library in some tests to extract those tests to a separate module with independent set of libraryDependencies.
Short summary: I would like to change the default publishTo with an sbt task, but only in some cases. I'm trying to do something like:
val setSnapshot = taskKey[Unit]("changeRepo")
setSnapshot := {
System.out.println(publishTo.value)
publishTo in ThisBuild := Some("test" at "snapshot.myrepository")
System.out.println(publishTo.value)
}
name := "Hello"
version := "1.0"
scalaVersion := "2.10.2"
publishTo in ThisBuild := Some("test" at "release.myrepository")
However, the publishTo does not change it's value. I learned that setting keys are assigned only once. Is publishTo a setting key? Is there no way to change the target later?
Context:
We want our server to build snapshots on any commit and releases on tags. We want it to release to two different repositories. Snapshots go in one and releases in another one. Is there a way to even change the isSnapshot configuration?
Ideally we would like to give our CI runner different commands it could run, like:
sbt setSnapshot publish
sbt setRelease publish
setRelease and setSnapshot would set the corresponding destination.
sbt publish
Alternatively if it was possible to just use publish, and then check if "isSnapshot" is true or false and then publish in one or the other repository. However, I haven't even figured out how isSnapshot can be modified, without touching the build.sbt-file itself.
I've been going through some of the build.sbt documentation, but I haven't found the right page yet...
https://www.scala-sbt.org/1.0/docs/Getting-Started.html
https://www.scala-sbt.org/1.0/docs/Task-Graph.html
Am I attacking this problem from a completely wrong angle?
there is an example in the sbt documentation on how to publish to separate snapshot repository:
publishTo := {
val nexus = "https://my.artifact.repo.net/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
see here for more details: https://www.scala-sbt.org/1.x/docs/Publishing.html#Define+the+repository
What I was looking for was something like mentioned here
isSnapshot can be manually set:
sbt 'set isSnapshot := true' isSnapshot
> ..
> true
Also, as lev brought up, the version can set the isSnapshot setting. Which basically leads to the same solution (but that was my missing piece).
sbt 'set version := "1.0"' isSnapshot
> ..
> false
when setting the version number to something including the keyword SNAPSHOT (please not it is case sensitive) it will result in a snapshot
sbt 'set version := "1.0-SNAPSHOT"' isSnapshot
> ..
> true
I have an sbt project that I need publish-local and then use it from an other project as a "libraryDependencies". It all builds fine but the groupId of the artifact is the same as the name of it. Can I specify the groupId somehow in my build.sbt?
There is organization setting for this purpose.
An example from AkkaBuild.scala
lazy val buildSettings = Seq(
organization := "com.typesafe.akka",
version := "2.4-SNAPSHOT",
scalaVersion := Dependencies.Versions.scalaVersion,
crossScalaVersions := Dependencies.Versions.crossScala
)
My company is switching from ant to sbt to ease Scala integration into our huge Java existing code (smart move if you ask me).
After compiling, we usually post-process all the generated .class with a tool of our own which is a result of the compilation.
I have been trying to do the same in sbt and it appears more complicated than expected.
I tried:
calling our postprocessor with fullRunTask. Works fine but we would like to pass "products.value" to look for the .class files and it does not work
another and even better solution would be to extend compile (compile in Compile ~= { result => ...). But I did not found how the code after "result =>" can call our postprocessor
we are looking at other solutions: multiple projects, one for the postprocessor, one for the rest of the code and this would clean but because the source code is entangled, this is not as easy as it seems (and we still would have the first problem)
Any help?
I would just write a simple plugin that runs after the other stages. It can inspect the target folder for all the .class files.
You could then do something like sbt clean compile myplugin in your build server.
This is the approach taken by the proguard plugin[1]. You could take a look at that as a starting point.
[1] https://github.com/sbt/sbt-proguard
Finally, I found a solution after reading "SBT in Action" and other documents. It is very simple but understanding SBT is not (at least for me).
name := "Foo"
version := "1.0"
scalaVersion := "2.11.0"
fork := true
lazy val foo = TaskKey[Unit]("foo")
val dynamic = Def.taskDyn {
val classDir = (classDirectory in Compile).value
val command = " Foo "+classDir
(runMain in Compile).toTask(command)
}
foo := {
dynamic.value
}
foo <<= foo triggeredBy(compile in Compile)
The sample project contains a Foo.scala with the main function
I am trying to import akka.dispatch.Future in my class but the compiler is unable to find that particular package. The one that it's able to find is akka.dispatch.Futures.
Can somebody point out what I might be doing wrong? My build.sbt is as follows:
name := "SomeApp"
version := "0.1"
scalaVersion := "2.10.1"
libraryDependencies ++= Seq("com.typesafe.akka" %% "akka-actor" % "2.1.2")
It's all in the docs: http://doc.akka.io/docs/akka/2.1.2/project/migration-guide-2.0.x-2.1.x.html
See the "Pieces Moved to Scala Standard Library" section.