Bram Meerten
Bram Meerten

Reputation: 97

Building a multi module maven project with Skaffold and Jib

Is it possible to build a multi module maven project with skaffold and jib builder?

My project structure:

my-project-parent-module
- my-project-main-module
- my-project-lib-module

my-project-main-module contains the Main class, and has the jib plugin configured, and has a dependency on my-project-lib-module. The lib-module doesn't have jib configured, because no image is needed.

The documentation has an example of a multimodule skaffold:

build:
  artifacts:
  - image: image1 # jib artifact
    jib:
      fromImage: image2
    requires:
    - image: image2
  - image: image2 # base image artifact

But this is a different scenario, because both modules produce an image (via jib).

Below is one of the skaffold configurations I tried:

apiVersion: skaffold/v2beta29
kind: Config
metadata:
  name: my-project
build:
  local:
    push: false
  artifacts:
    - image: my-image-name
      context: ./
      jib:
        project: com.example:my-project-main-module
  ...

Upvotes: 2

Views: 845

Answers (2)

Zhenya
Zhenya

Reputation: 79

continue last answer. You also should add your skaffold.yaml to parent project

apiVersion: skaffold/v4beta11
kind: Config
metadata:
  name: inner-service
build:
 artifacts:
    - image: docker.registry.com/inner-service
      jib:
      project: com.example.inner_service:inner-service
manifests:
   rawYaml:
     - inner-service/k8s/deployment.yaml

Upvotes: 0

Brian de Alwis
Brian de Alwis

Reputation: 2974

When you specify a project:, Skaffold will invoke something like:

mvn --projects com.example:my-project-main-module --also-make jib:build

This will be executed from the context directory. The --also-make causes Maven to rebuild any dependencies (like your lib-module) as necessary.

Make sure you can run the command-line above separately from Skaffold. Check that your lib-module is included as a <module> in your top-level pom.xml, and that your main-module has a <dependency> to your lib-module.

Upvotes: 2

Related Questions