Using SBT-Assembly with multi-module project.

3,370 views
Skip to first unread message

Edmondo Porcu

unread,
May 21, 2012, 2:56:56 PM5/21/12
to simple-b...@googlegroups.com
Dear all,
I have a problem when trying to use the SBT in a multi-module project.
If I put the settings as suggested in the wiki inside my build.sbt


import sbtassembly.Plugin._
import AssemblyKeys._

---- my build stuff
assemblySettings

Only the scala jar is bundled into the target jar.

If I put that into my build definition like that:


import sbt._
import Keys._

import sbtassembly.Plugin._
import AssemblyKeys._



object Search extends Build {


lazy val search = Project(id = "Search",
base =
file("."),settings=assemblySettings) aggregate(common, lucene,tools)


lazy val common = Project(id = "search-common",
base = file("common"),settings=assemblySettings)

lazy val lucene = Project(id = "search-lucene",
base =
file("lucene"),settings=assemblySettings) dependsOn(common)

lazy val tools = Project(id = "search-tools",
base =
file("tools"),settings=assemblySettings) dependsOn(common,lucene)

}


Then I get something like:

[error] References to undefined settings:
[error]
[error] search-tools/*:cache-directory from
search-tools/*:assembly-package-dependency
[error]
[error] search-lucene/test:test from search-lucene/*:test
[error]
[error] search-common/runtime:dependency-classpath from
search-common/*:dependency-classpath(for assembly)
[error]
[error] search-tools/*:cache-directory from search-tools/*:assembly
[error]
[error] search-lucene/*:cache-directory from
search-lucene/*:assembly-package-dependency
[error]
[error] search-lucene/*:cache-directory from search-lucene/*:assembly
[error]
[error] search-lucene/runtime:main-class from
search-lucene/*:main-class(for assembly)
[error]
[error] Search/test:test from Search/*:test
[error]
[error] search-tools/*:target from search-tools/*:target(for assembly)
[error] Did you mean search-tools/*:target(for assembly) ?
[error]
[error] search-tools/runtime:full-classpath from
search-tools/*:full-classpath(for assembly)
[error]
[error] Search/*:cache-directory from Search/*:assembly
[error]
[error] search-common/*:target from search-common/*:target(for assembly)
[error] Did you mean search-common/*:target(for assembly) ?
[error]
[error] search-tools/*:package-options from
search-tools/*:assembly-package-scala
[error] Did you mean search-tools/*:package-options(for assembly) ?
[error]
[error] search-tools/*:cache-directory from
search-tools/*:assembly-package-scala
[error]
[error] search-tools/*:library-dependencies from
search-tools/*:library-dependencies
[error]
[error] search-tools/runtime:dependency-classpath from
search-tools/*:dependency-classpath(for assembly)
[error]
[error] search-common/runtime:full-classpath from
search-common/*:full-classpath(for assembly)
[error]
[error] search-lucene/*:target from search-lucene/*:target(for assembly)
[error] Did you mean search-lucene/*:target(for assembly) ?
[error]
[error] search-common/*:package-options from
search-common/*:assembly-package-scala
[error] Did you mean search-common/*:package-options(for assembly) ?
[error]
[error] search-common/*:cache-directory from
search-common/*:assembly-package-scala
[error]
[error] search-common/compile:package-options from
search-common/*:package-options(for assembly)
[error]
[error] Search/runtime:dependency-classpath from
Search/*:dependency-classpath(for assembly)
[error]
[error] search-lucene/runtime:dependency-classpath from
search-lucene/*:dependency-classpath(for assembly)
[error]
[error] search-common/*:cache-directory from search-common/*:assembly
[error]
[error] Search/runtime:full-classpath from
Search/*:full-classpath(for assembly)
[error]
[error] Search/*:resolvers from Search/*:resolvers
[error]
[error] search-tools/compile:package-options from
search-tools/*:package-options(for assembly)
[error]
[error] Search/compile:package-options from
Search/*:package-options(for assembly)
[error]
[error] Search/runtime:main-class from Search/*:main-class(for assembly)
[error]
[error] Search/*:target from Search/*:target(for assembly)
[error] Did you mean Search/*:target(for assembly) ?
[error]
[error] search-lucene/*:library-dependencies from
search-lucene/*:library-dependencies
[error]
[error] search-lucene/runtime:full-classpath from
search-lucene/*:full-classpath(for assembly)
[error]
[error] search-common/runtime:main-class from
search-common/*:main-class(for assembly)
[error]
[error] search-common/test:test from search-common/*:test
[error]
[error] search-lucene/compile:package-options from
search-lucene/*:package-options(for assembly)
[error]
[error] search-tools/test:test from search-tools/*:test
[error]
[error] search-lucene/*:package-options from
search-lucene/*:assembly-package-scala
[error] Did you mean search-lucene/*:package-options(for assembly) ?
[error]
[error] search-lucene/*:cache-directory from
search-lucene/*:assembly-package-scala
[error]
[error] search-common/*:cache-directory from
search-common/*:assembly-package-dependency
[error]
[error] search-tools/runtime:main-class from
search-tools/*:main-class(for assembly)
[error]
[error] Search/*:package-options from Search/*:assembly-package-scala
[error] Did you mean Search/*:package-options(for assembly) ?
[error]
[error] Search/*:cache-directory from Search/*:assembly-package-scala
[error]
[error] Search/*:cache-directory from Search/*:assembly-package-dependency
[error]
[error] Use 'last' for the full log.

Could you please help me?

Best regards
Edmondo

eugene yokota

unread,
May 21, 2012, 10:53:50 PM5/21/12
to simple-b...@googlegroups.com
Hi Edmondo,

You only need to add assemblySettings to the project you want the assembly jar out of.
Also, you probably should pass in Defaults.defaultSettings ++ assemblySettings instead of just
assemblySettings for project to do other things like compiling.

-eugene

Edmondo Porcu

unread,
May 22, 2012, 3:55:09 AM5/22/12
to simple-b...@googlegroups.com
Dear Eugene,
Thank you for your answer

If I just add assemblySettings in my build.sbt only the scala library
is packaged :(

Best

2012/5/22 eugene yokota <eed3...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-build-tool/-/QOX1IfEfvSkJ.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-build-t...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/simple-build-tool?hl=en.

Edmondo Porcu

unread,
May 22, 2012, 11:38:44 AM5/22/12
to simple-b...@googlegroups.com
Should I put DefaultSettings.buildSettings ++ assemblySettings in my build.sbt?
Best
Edmondo

2012/5/22 Edmondo Porcu <edmond...@gmail.com>:

eugene yokota

unread,
May 22, 2012, 12:14:25 PM5/22/12
to simple-b...@googlegroups.com
Not really, if you already have build.scala, you don't need build.sbt.
You should add DefaultSettings.buildSettings ++ assemblySettings to
settings param of the project you need to assemble.

Then within sbt, you need to switch the project as

> project foo

and then run assembly.

-eugene

Edmondo Porcu

unread,
May 23, 2012, 1:47:42 PM5/23/12
to simple-b...@googlegroups.com
Dear Eugene,
thank you for the support.

If I add the assemblySettings to my subprojects, they get correctly
packaged in a jar (one per subproject). However, my "main" jar does
not contain the others:


object Search extends Build {


lazy val search = Project(id = "Search",
base =
file("."),settings=Defaults.defaultSettings++ assemblySettings)
aggregate(common, lucene,tools)


lazy val common = Project(id = "search-common",
base =
file("common"),settings=Defaults.defaultSettings)

lazy val lucene = Project(id = "search-lucene",
base =
file("lucene"),settings=Defaults.defaultSettings) dependsOn(common)

lazy val tools = Project(id = "search-tools",
base =
file("tools"),settings=Defaults.defaultSettings)
dependsOn(common,lucene)

}

Is that because sbt-assembly does not process the aggregate clause?

Best
Edmondo
2012/5/22 eugene yokota <eed3...@gmail.com>:

eugene yokota

unread,
May 23, 2012, 2:18:07 PM5/23/12
to simple-b...@googlegroups.com
On Wed, May 23, 2012 at 1:47 PM, Edmondo Porcu <edmond...@gmail.com> wrote:
> Is that because sbt-assembly does not process the aggregate clause?

I think it didn't aggregate because you overrode the `assembly` task.
It should automatically aggregate if you don't set assemblySettings for it.

Here's a simple aggregation sample:

import sbt._
import Keys._

object Builds extends Build {
lazy val root = Project("root", file("."),
settings = buildSettings) aggregate(app)
lazy val app = Project("app", file("app"),
settings = buildSettings ++ sbtassembly.Plugin.assemblySettings)

lazy val buildSettings = Defaults.defaultSettings ++ Seq(
version := "0.1-SNAPSHOT",
organization := "com.example",
scalaVersion := "2.9.1"
)
}

Full sample is available [eed3si9n/sbt-assembly-full-config-sample][1].

-eugene

[1]: https://github.com/eed3si9n/sbt-assembly-full-config-sample

Edmondo Porcu

unread,
May 23, 2012, 2:37:47 PM5/23/12
to simple-b...@googlegroups.com
Dear Eugene,
thank you. I have tried with your suggestion, removing the
assemblySettings from the settings of my top project, in my case it is
search, in your case it is root.

Now, no jar is generated for the search project. Before, a jar
containing only the scala library classes was generated.

:((((
Thank you for your help


object Search extends Build {


lazy val search = Project(id = "Search",
base = file(".")) aggregate(common, lucene,tools)


lazy val common = Project(id = "search-common",
base =
file("common"),settings=Defaults.defaultSettings ++ assemblySettings)

lazy val lucene = Project(id = "search-lucene",
base =
file("lucene"),settings=Defaults.defaultSettings ++ assemblySettings)
dependsOn(common)

lazy val tools = Project(id = "search-tools",
base =
file("tools"),settings=Defaults.defaultSettings ++ assemblySettings)
dependsOn(common,lucene)

}




2012/5/23 eugene yokota <eed3...@gmail.com>:

eugene yokota

unread,
May 23, 2012, 3:10:56 PM5/23/12
to simple-b...@googlegroups.com
Do you actually have source under your root ("Search") project?
Maybe you've hit an sbt issue here, but I usually use an empty project for root.

-eugene

Egon Nijns

unread,
Jun 20, 2013, 3:47:22 AM6/20/13
to simple-b...@googlegroups.com
I'm running into the same problem. The classfiles of the library project are not being included in the resulting jar.

This is my sbt build definition: https://gist.github.com/enijns/5820924#file-gistfile1-scala

Is there any way to work around this issue?

egon.

eugene yokota

unread,
Jun 20, 2013, 11:54:51 AM6/20/13
to simple-b...@googlegroups.com
Hi Egon,

Could open a [github issue][1] on sbt-assembly describing:
1. steps to reproduce the issue.
2. actual output.
3. expected output.

Specifically regarding "The classfiles of the library project are not being included in the resulting jar.",
when you run assembly, which project are you running it from?
By "the library project" do you mean wintermute-rules? Does `run` command work?

-eugene

Egon Nijns

unread,
Jun 20, 2013, 1:57:00 PM6/20/13
to simple-b...@googlegroups.com
Thank you Eugene,

Yes, wintermute-rules is the library project. I run the assembly task from the wintermute-app project.

But you are right: the run command also doesn't work anymore. So: this may be a problem with my build or an SBT bug.
Any ideas what might be causing this?

If you like: tomorrow I should be able to prepare a simple testcase.

egon.

Egon Nijns

unread,
Jun 21, 2013, 3:09:30 AM6/21/13
to simple-b...@googlegroups.com
Hi,

I found out what is causing this: I'm using externalIvySettings() with a custom ivysettings.xml file.
(this is required for pulling in dependencies from our custom ivy repository) - see also https://groups.google.com/d/msg/simple-build-tool/mb7w7fqRoGw/LC1ObK1zbyoJ

If I get rid of this externalIvySettings in my build, 'run' and 'assembly' are working fine again.

I'm not sure of the best way to proceed with this: I need to be able to reuse the home-made dependencies from our in-house ivy repository, but using externalIvySettings seems to break too many things...

regards,
Egon.

Egon Nijns

unread,
Jun 21, 2013, 5:04:56 AM6/21/13
to simple-b...@googlegroups.com
An update: I had an issue with classpathConfiguration settings in my build.sbt.

After removing the following settings I get the correct dependency-classpath in my 'app' project
//classpathConfiguration in Compile := config("compile")
//classpathConfiguration in Runtime := config("runtime")
//classpathConfiguration in Test := config("test")    

Now the run and assembly tasks are working fine.

I had to declare some of our custom dependencies using inline ivy xml because I now need some configuration mappings.
ivyXML :=                                                                                   
  <dependencies>                                                                            
    <dependency org="uz" name="lis" rev="latest.integration" conf="*->default">             
    </dependency>                                                                           
  </dependencies>                                                                           

I'm not sure if this is possible without inline ivyXML declarations...

egon.

Mark Harrah

unread,
Jun 21, 2013, 8:07:15 AM6/21/13
to simple-b...@googlegroups.com
On Fri, 21 Jun 2013 02:04:56 -0700 (PDT)
Egon Nijns <egon....@gmail.com> wrote:

> An update: I had an issue with classpathConfiguration settings in my
> build.sbt.
>
> After removing the following settings I get the correct
> dependency-classpath in my 'app' project
> //classpathConfiguration in Compile := config("compile")
> //classpathConfiguration in Runtime := config("runtime")
> //classpathConfiguration in Test := config("test")
>
> Now the run and assembly tasks are working fine.
>
> I had to declare some of our custom dependencies using inline ivy xml
> because I now need some configuration mappings.
> ivyXML
> :=
>
>
> <dependencies>
>
> <dependency org="uz" name="lis" rev="latest.integration"
> conf="*->default">
>
> </dependency>
>
>
> </dependencies>
>
>
> I'm not sure if this is possible without inline ivyXML declarations...

I'm not sure I understand correctly, but I'm pretty sure you can say ... % "*->default" in a normal inline dependency definition.

-Mark
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
> To post to this group, send email to simple-b...@googlegroups.com.
> Visit this group at http://groups.google.com/group/simple-build-tool.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Egon Nijns

unread,
Jun 24, 2013, 5:31:30 AM6/24/13
to simple-b...@googlegroups.com
Of course. I don't know why I didn't even try this.

thank you Mark!
Reply all
Reply to author
Forward
0 new messages