question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jib doesn't update images when included Gradle projects change

See original GitHub issue

Description 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'
  1. If I intentionally introduce a compile-time error in some-lib and run gradle jibDockerBuild on the app, the build fails, so I know the right library code is being compiled.
  2. 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 new LastTagTime.
  3. 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 old some-lib code.
  4. If I open a shell, I can see some-lib.jar in /apps/libs, which isn’t getting updated.
  5. If I run gradle build before gradle 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:closed
  • Created 4 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
emersonfcommented, Jun 6, 2019

I think I found the culprit, and it’s not Spring.

Our some-libs 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 a build or assemble task during the Building 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.

1reaction
garypcommented, Sep 19, 2019

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 on tasks.assemble. Depending on tasks.jar was not sufficient.

From the logs, it seems the reason is that with the java-library plugin tasks.jar only builds the current project’s jar file and does not create any dependencies on the jar tasks of sub-project dependencies. Whereas tasks.assemble does create a dependency on the jar 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):

tasks.matching {
    it.name.startsWith('jib')
}.configureEach {
    it.dependsOn tasks.named('assemble')
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found