how to define my artifact groupId? - sbt

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
)

Related

SBT dependencyOverrides in a scope doesn't seem to work as expected

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.

build.sbt change setting with task

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

it:scalastyle not working for integration tests' folder

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

Conditional libraryDependencies in SBT

I'd like to create conditional library dependency in build.sbt file.
I'm looking for similar behavior to maven profiles where I can enter a profile / system variable in the command line and have SBT define libraryDependencies according to it.
i.e. if system variable was supplied - add HBase client dependency else don't.
Any help would be appreciated.
Thanks,
Ido
Does this help?
val my_version = System.getProperty("my_version", "")
libraryDependencies ++= (
if (my_version != "" )
("org.example.code" %% "my_library" % my_version) :: Nil
else
Nil
)
Only adds to library dependency, if a version is specified

akka.dispatch.Future not found

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.

Resources