Hubert Bratek
Hubert Bratek

Reputation: 1104

Sbt multiple projects with commons

I have a project with 4 modules and one common module which should be added to every jar file. However, it is configured in the build.sbt in parent module

lazy val root = (project in file("."))
  .aggregate(P1, Commons, P2, P3, P4)

lazy val Commons = (project in file("commons"))

lazy val P1 = (project in file("p1"))
  .dependsOn(Commons)

DOCKERFILE:

FROM amazonlinux:2018.03 as build

ARG SCALA_VERSION
ARG SBT_VERSION
ARG JAVA_VERSION

RUN yum install -y java-${JAVA_VERSION}-openjdk-devel
RUN yum install -y https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.rpm
RUN yum install -y https://dl.bintray.com/sbt/rpm/sbt-${SBT_VERSION}.rpm

WORKDIR root/P1

ADD ./project/plugins.sbt project/
ADD ./project/build.properties project/
ADD build.sbt .
RUN sbt update

COPY . .

RUN sbt clean assembly

RUN cp target/scala-2.12/P1-assembly-1.0-SNAPSHOT.jar P1.jar

FROM openjdk:8-jre-alpine

COPY --from=build \
   root/P1/P1.jar .

ENTRYPOINT ["java", "-jar", "/P1.jar"]

However, when I am creating dockerfile for each of the P1, P2, P3, P4 it doesn't include the added Commons. How am I supposed to do that? Should I change anything in my build.sbt files in every project?

Upvotes: 2

Views: 286

Answers (1)

baitmbarek
baitmbarek

Reputation: 2518

Can you try to replace "aggregate" with "dependsOn" ? Aggregate means the task you are running will also run on aggregated projects which is not what you expect.

edit : "aggregate" is useful to run tests on each sub-module for example while running a "sbt clean test" on root project

Upvotes: 1

Related Questions