Getting sbt-assembly working
Asked Answered
S

1

13

So thus far I've been compiling my Scala project with SBT (via Typesafe stack). I want to run the code across several machines now, via sbt-assembly. Following directions, the only one change I made was in my project/Build.scala file. Here is the related part:

resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
resolvers += "artifactory" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases",
libraryDependencies += "com.eed3si9n" % "sbt-assembly" % "0.8.3"

When I run sbt compile however, I get this error:

sbt.ResolveException: unresolved dependency: com.eed3si9n#sbt-assembly/scala_2.9.1/sbt_0.11.2;0.8.3: not found.

What am I doing wrong?

Thanks!

EDIT Created a build.sbt file in the same folder as Build.scala (folder is /project/) and have these two lines in it:

Seq[Setting[_]](resolvers += "artifactory" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases",
                addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.3"))

Now the error is:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.eed3si9n#sbt-assembly;0.8.3: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]      com.eed3si9n:sbt-assembly:0.8.3 (sbtVersion=0.11.2, scalaVersion=2.9.1)
[warn] 
[error] {file:/Users/myname/current/projectname/project/}default-d7da9a/*:update: sbt.ResolveException: unresolved dependency: com.eed3si9n#sbt-assembly;0.8.3: not found

EDIT 2 Hm, after I do a successful sbt compile, should I just be able to enter the sbt console and type in assembly?

> assembly
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Not a valid configuration: assembly
[error] Not a valid key: assembly
[error] assembly
[error]   

EDIT 3 JK got it. Had to add the build.sbt info as specified in the GitHub README.

Shcherbakov answered 11/6, 2012 at 21:58 Comment(1)
"info as specified in the GitHub README" - link please?Amman
I
10

There are two points here. One is that SBT plugins are not just library dependencies -- in particular, they use the current SBT version in a similar way that other Scala libraries use the Scala version. The other is that libraryDependencies in project/Build.scala affects the dependencies for the project, not for the build.

An SBT full build is itself an SBT project, just located one level down the directory tree, and so can have a build of its own configured the same way a normal build is. Unlike a normal build, where going for a "full build" is necessary under a handful of circumstances, there is almost never a reason to use a full build for a build, so using .sbt files located in project/ is almost always sufficient.

The other issue is the versioning. SBT has a utility function called addSbtPlugin that handles everything for you. It takes a moduleID and adds all the necessary SBT and Scala versioning information.

So, to get sbt-assembly working in a full build, you create a .sbt file in under project/ (conventionally either project/build.sbt or project/plugins.sbt) and place your build's resolvers and dependencies there:

resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.3")
Imprimis answered 11/6, 2012 at 22:19 Comment(8)
What is the format of the arguments to addSbtPlugin? What would I do for sbt-assembly?Shcherbakov
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.3"), so the part of your build.scala that deals with settings should look like: Seq[Setting[_]](resolvers += ..., resolvers += ..., addSbtPlugin(...))`Imprimis
Actually, it suddenly occurs to me that you might be putting it in the wrong file altogether. If this is project/Build.scala, then putting it in there will do no good at all (it will declare that your source code depends on sbt-assembly, not the project). To make the project use it, put the settings for it either in project/build.sbt or project/project/Build.scala (preferably the former, as there is almost never a reason to use a full build for the project's meta-build).Imprimis
Hm, do I do the Seq[Setting[_]] on the entire settings assignment, or just the part for the sbt-assembly plugin? EDIT Just got your new message.. let me try again.Shcherbakov
So should I just create a build.sbt in the same folder as my Build.scala file, add those 2 lines, and then do sbt compile?Shcherbakov
Yes; I'm editing my answer now to make this (and the reason for it) clearer.Imprimis
I've edited my original question to reflect new errors... thanks for your help!Shcherbakov
There, done editing. To answer your new question: remove the "Seq[Setting](" from the first line, the comma, and the final closing parenthesis at the end, and put a blank line between the two.Imprimis

© 2022 - 2024 — McMap. All rights reserved.