2

For scala peoples it must be an obvious answer. But for new scala user like me it's not ;)

I have two scala modules (package) with "standard" hierarchy (spi2wb and mdio) that I want to use in a third project/module.

The files directory hierarchy for my spi2wb module is following:

├── build.sbt
├── Makefile
├── README.md
└── src
    ├── main
    │   └── scala
    │       └── spi2wb.scala
    └── test
        └── scala
            └── test_spi2wb.scala

In scala source I added package header :

  • in src/main/scala/spi2wb.scala
package spi2wb
  • and in src/main/scala/mdio.scala
package mdio

This two projects are on my home pc hard drive. I wonder how to do to use these two modules in my third project in an "import *" like fashion :

import mdio._
import spi2wb._

Again, it's maybe straightforward but I can't found a simple method to do it.

FabienM
  • 3,421
  • 23
  • 45
  • Maybe this helps: https://stackoverflow.com/a/40414593. I think you also have to put your files in a folder corresponding to your package name. – Saskia Oct 02 '19 at 11:15
  • It's really complex. There is no solution to juste says "hey package is here" giving the directory then use it with import ? – FabienM Oct 02 '19 at 12:44
  • If you want to use it in a different project I don't think so. – Saskia Oct 02 '19 at 13:44

1 Answers1

3

I found a solution with publishLocal.

In build.sbt of each modules I added a version and organization :

version := "1.0-rc2" 

organization := "org.armadeus"

Then for each submodule I launched the publishLocal commands :

$ sbt publishLocal

And in the sbt of my main "top" module I added the dependencies :

libraryDependencies ++= Seq("org.armadeus" %% "spi2wb" % "1.1")

libraryDependencies ++= Seq("org.armadeus" %% "mdio" % "1.0-rc2")

Note to not forget the dual %% symbol as first separator to make it works with your scala version.

I don't know if it's the good way to do it but it's working.

FabienM
  • 3,421
  • 23
  • 45
  • 1
    Publishing is the normal way of sharing stuff in the Scala community so publish local makes sense. We do source dependencies (as opposed to published dependencies) in rocket-chip but it's kind of a pain. – Jack Koenig Oct 02 '19 at 18:01
  • Hi @jkoenig, if you do "source dependencies" does it mean that you have only one package and build.sbt config file ? – FabienM Oct 03 '19 at 07:32