Sparker0i
Sparker0i

Reputation: 1861

SBT Assembly remove classes from another JAR

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?

Upvotes: 2

Views: 268

Answers (1)

Ga&#235;l J
Ga&#235;l J

Reputation: 15230

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

Upvotes: 3

Related Questions