jib doesn't update images when included Gradle projects change
See original GitHub issueDescription of the issue:
gradle jibDockerBuild
isn’t creating new Docker images when code in Gradle included builds changes.
For the time being, I’m calling gradle build jibDockerBuild
to work around this but that’s counter-intuitive.
Expected behavior:
When code in an included build changes and gradle jibDockerBuild
is re-run, a new image should be built containing the latest code from both the project and its included builds.
Steps to reproduce:
Assume a composite Gradle build where an app’s build.gradle
declares a dependency on a library using
implementation("foo:some-lib:1.0.0") { changing = true }
and its settings.gradle
contains
includeBuild '../some-lib'
- If I intentionally introduce a compile-time error in
some-lib
and rungradle jibDockerBuild
on the app, the build fails, so I know the right library code is being compiled. - If I make a non-breaking change in
some-lib
,jibDockerBuild
succeeds but the Docker image it constructs is identical to the one before the change, it just has a newLastTagTime
. - If I make a change to both the app and to the library and run
gradle jibDockerBuild
, a new image is built, but it still executes oldsome-lib
code. - If I open a shell, I can see
some-lib.jar
in/apps/libs
, which isn’t getting updated. - If I run
gradle build
beforegradle jibDockerBuild
, the library is updated.
Environment: macOS, JDK8, Gradle
jib-gradle-plugin
Configuration:
jib {
from {
image = "gcr.io/distroless/java:debug"
}
to {
image = "foo/bar"
}
container {
jvmFlags = ["-Duser.timezone=UTC"]
ports = ["80"]
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Jib plugin not able to access project.version as updated by ...
The publish task is able to access the version as updated by the gitflowsemver plugin, but when I try to build a docker...
Read more >Building Java container images using Jib - Snyk
In this article, we will look at Jib, a 100% Java-based tool for Java developers to build highly optimized images for their Java...
Read more >google/jib - Gitter
Gradle build and docker build. Now I have one which is Gradle jib —image=blabla. It works quite well, I even implemented the caching...
Read more >Maven packages in the Package Repository - GitLab Docs
You can create a package each time the main branch is updated. Authenticate with a CI job token in Gradle. Add a deploy...
Read more >How to build Gradle projects with GitHub Actions - Tom Gregory
Fortunately action/setup-java@v2 already has Gradle caching built in and we just need to enable it! It's literally a one line change to pass...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I found the culprit, and it’s not Spring.
Our
some-lib
s use the Java Library plugin instead of the JAR plugin to reduce compile classpath sizes and to avoid inadvertent transient dependencies, as recommended by Gradle. During compilation, If i’m reading this right and judging by the console output, JARs aren’t built when using the Java Library plugin … “consumers will use the output classes directory of this project directly on their compile classpath, instead of the jar file if the project uses the Java plugin”. I assume “use” means reference, not actually copy.My guess is that
jibDockerBuild
isn’t seeing the updated.class
files of the included builds during the “Building classes layer…” step and creating stale images as a result. But it is seeing the updated JAR files of the included builds that are created by abuild
orassemble
task during theBuilding dependencies layer...
step and updating the image correctly.If that’s right, this could be a bigger issue, because it would affect all projects using Java Library plugins, irrespective of included builds.
I have a similar issue to #1776, where running
jibDockerBuild
fails because it can’t find the jar files for sub-project dependencies. I tried the solution suggested by @loosebazooka above and could only get the build to pass when I added a dependency ontasks.assemble
. Depending ontasks.jar
was not sufficient.From the logs, it seems the reason is that with the
java-library
plugintasks.jar
only builds the current project’s jar file and does not create any dependencies on thejar
tasks of sub-project dependencies. Whereastasks.assemble
does create a dependency on thejar
tasks of all sub-project dependencies.For reference, this is what I ended up adding in my
build.gradle
(modified from @loosebazooka’s suggestion in order to work with gradle’s new task configuration avoidance API):