You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Palantir gradle-docker-plugin无法将JAR包添加至新Docker镜像

Troubleshooting: Spring Boot JAR Not Added to Docker Image with Palantir Gradle Plugin

Hey there! As someone who’s fumbled through early CI setup with Docker, Gradle, and Jenkins, I totally get how frustrating this roadblock can be. Let’s break down the most common issues and fixes step by step:

1. Fix Gradle Task Dependencies

The #1 cause here is your dockerBuild task running before the build task finishes generating your Spring Boot JAR. The Palantir plugin doesn’t automatically link these tasks, so you need to explicitly set the dependency.

Add this to your build.gradle file:

// Option 1: Directly link tasks
tasks.dockerBuild.dependsOn(tasks.build)

// Option 2: Set within the docker plugin config
docker {
    // ... your existing config ...
    dependsOn tasks.build
}

2. Verify Dockerfile Paths & Context Directory

Spring Boot’s build task outputs JARs to build/libs/ by default. You need to make two key checks:

  • Your Dockerfile’s ADD command uses a path relative to the Docker context directory
  • The Palantir plugin’s context directory includes the build/libs folder

Example Dockerfile (place in src/main/docker/ or project root):

FROM openjdk:17-jdk-slim
VOLUME /tmp
# Use a wildcard to match your JAR (adjust if you have a custom naming pattern)
ADD build/libs/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Update Gradle Docker Plugin Config:

Ensure the context directory is set to your project root so it can access the generated JAR:

docker {
    name "${project.group}/${project.name}:${project.version}"
    // Point to your Dockerfile's location
    dockerfile file('src/main/docker/Dockerfile')
    // Set context to project root (includes build/libs)
    contextDir file('.')
}

3. Confirm the JAR Exists in Jenkins Workspace

Sometimes the issue is simpler than you think—your build task might be failing silently in Jenkins, or the JAR isn’t where you expect. Add a debug step to your Jenkins pipeline to verify:

# Add this before your Gradle dockerBuild step
echo "Checking for generated JAR files:"
ls -la build/libs/

If no JAR is listed, fix your Spring Boot build task first (check for compilation errors, test failures, etc.).

4. Check Jenkins Workspace Permissions

Occasionally, the Jenkins user account might lack write access to the build directory, preventing the JAR from being saved. Ensure the Jenkins user has read/write permissions for your project workspace.

Quick Local Validation Tip

Run the build locally first with ./gradlew clean dockerBuild. If the image builds correctly on your machine, the issue is almost certainly with Jenkins configuration (permissions, workspace setup, or missing steps).


内容的提问来源于stack exchange,提问作者ParkCheolu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:45:54