1

I have a skaffold + jib + jib-maven-plugin setup that I use for development.

I run skaffold dev and it builds the project, container image and deploys to my local k8s cluster. Whenever I touch the source code it rebuilds and redeploys containers. The rebuilds trigger maven goals to compile & run unit tests.

This works fine, but is a bit slow since maven recompiles all sources everytime sth changes so I thought I'd give gradle setup a shot and test its incremental compilation capabilities for my project.

It works great, but there's one thing I am bit confused about, that is that jib gradle plugin seems not to be running the test tasks for my sources at all.

$> gradle jibDockerBuild --dry-run 

:my-module:generateMainEffectiveLombokConfig1 SKIPPED
:my-module:compileJava SKIPPED
:my-module:processResources SKIPPED
:my-module:classes SKIPPED
:my-module:jibDockerBuild SKIPPED

If I run gradle build the tests tasks are triggered:

$> gradle build --dry-run
:my-module:generateMainEffectiveLombokConfig1 SKIPPED
:my-module:compileJava SKIPPED
:my-module:processResources SKIPPED
:my-module:classes SKIPPED
:my-module:jar SKIPPED
:my-module:assemble SKIPPED
:my-module:generateTestEffectiveLombokConfig1 SKIPPED
:my-module:compileTestJava SKIPPED
:my-module:processTestResources SKIPPED
:my-module:testClasses SKIPPED
:my-module:test SKIPPED
:my-module:check SKIPPED
:my-module:build SKIPPED

I trawled through jib and skaffold documentation and github issues, but I couldn't find anything related to running unit tests as part of the container image creation using jib.

I would think that running unit tests should be mandatory part of building an image and that either gradle jibDockerBuild would run it implicitly just like gradle build does or that skaffold via its integration with jib would somehow trigger those by perhaps running gradle test before jibDockerBuild, but it seems not to be the case.

So the question is how do I make sure my unit tests run when using skaffold with jib and gradle and what's the reason why it doesn't happen automatically....

artur
  • 1,710
  • 1
  • 13
  • 28

1 Answers1

2

You can compose testing together with jibDockerBuild by either invoking them together with gradle test jibDockerBuild or by defining a dependency in your configuration with jibDockerBuild.dependsOn test.

As to why it's not done by default -- user requirements differ. For example, you could be building an image prior to running integration tests using it. It's much easier to combine tasks than separate/disable them.

Elena Felder
  • 456
  • 3
  • 8
  • I think that if you run integration tests you want to run your unit tests before. I understand the point about composing, but then why isn't `gradle build` forcing you to explicitly depend on test task for the same reason? Since I use `skaffold` to call gradle then `test jibDockerBuild` is not an option without some custom skaffold configuration. `jibdockerBuild.dependsOn test` kind of works, though I have multiproject setup with common code in separate project in the repo. The tests of that project are not executed, only tests of the project that creates the container image. – artur Feb 07 '22 at 17:48
  • `gralde build` depends on a lot of things by its design: `jar`, `assemble`, `test`, `check`, etc. It is not that you always have to run the `build` task. Actually, I don't do it during development, because it does too many things and is slow. You can separately do `compileJava`, `javadoc`, `jar`, etc. You can compose these tasks however you like. – Chanseok Oh Feb 09 '22 at 01:00