2

This is the package structure of my repo:

src
|-- main
    |-- scala
        |-- me.sparker0i.spark
            |-- runner
                |-- Runner.scala
            |-- utils
                |-- Constants.scala
                |-- DatabaseUtils.scala
            |-- service
                |-- Service.scala
                |-- Transform.scala [extends Service]
                |-- Fetch.scala [extends Service]
                |-- <32 more>
            |-- Test.scala

I want to split this application into two such that one application remains the core, while the other uses the core jar as a libraryDependencies:

Core Repo structure:

src
|-- main
    |-- scala
        |-- me.sparker0i.spark
            |-- runner
                |-- Runner.scala
            |-- utils
                |-- Constants.scala
                |-- DatabaseUtils.scala
            |-- service
                |-- Service.scala
            |-- Test.scala

Independent Repo:

src
|-- main
    |-- scala
        |-- me.sparker0i.spark
            |-- service
                |-- Transform.scala [extends Service from Core Repo JAR]
                |-- Fetch.scala [extends Service from Core Repo JAR]
                |-- <32 more>

Now inside the Independent Repo, I've referenced the Core Repo JAR inside libraryDependencies. I need that Core JAR to run the test cases of the Independent Repo inside our Jenkins CICD, but not when I need to package the Independent Repo.

When I do sbt assembly, how do I ensure that I don't get the contents of the Core JAR inside the Independent JAR? The reason being I will be running the Main class inside the Core JAR, but will also be supplying the Independent JAR as a class path.

Is there some way the above requirement can be achieved using sbt?

Sparker0i
  • 1,787
  • 4
  • 35
  • 60

1 Answers1

3

You could declare the dependency with scope Provided. This is exactly meant for this use case, i.e. a dependency is provided somehow at runtime but not part of the package.

groupId % core % version % Provided
Gaël J
  • 11,274
  • 4
  • 17
  • 32
  • if my understanding is correct, then none of the other dependencies from the Core JAR will carry over to this Independent JAR while it is being `sbt assembly`ed right? – Sparker0i Aug 02 '21 at 20:06
  • 1
    That what I'd expect event though I'm not familiar with sbt-assembly. You can probably test it and confirm. – Gaël J Aug 02 '21 at 20:08