Search code examples
scalasbtchisel

How to use chisel module as package


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.


Solution

  • 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.