Search code examples
spring-bootkubernetesgradlegoogle-cloud-platformjib

Deploying Spring Boot app (based on Gradle) to Google Cloud Kubernetes Engine using Jib plugin gives error


I am following tutorial: https://codelabs.developers.google.com/codelabs/cloud-springboot-kubernetes?continue=https%3A%2F%2Fdevelopers.google.com%2Flearn%2Fpathways%2Fspringboot-google-cloud%23codelab-https%3A%2F%2Fcodelabs.developers.google.com%2Fcodelabs%2Fcloud-springboot-kubernetes#4 for Deployin a Spring Boot Java app to Kubernetes on Google Kubernetes Engine. I have my own sourcecode which is based on gradle and not on maven. I got stuck on the command:

./mvnw -DskipTests com.google.cloud.tools:jib-maven-plugin:build -Dimage=us-central1-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/codelabrepo/hello-java:v1

I have replaced it with:

./gradlew   com.google.cloud.tools:jib-maven-plugin:build -Dimage=us-central1-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/codelabrepo/hello-java:v1

But i am getting an error:

FAILURE: Build failed with an exception.

* What went wrong:
Cannot locate tasks that match 'com.google.cloud.tools:jib-maven-plugin:build' as project 'com.google.cloud.tools' not found in root project 'questy'.

My gradle file looks:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.0'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'org.bbbb'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'


repositories {
    mavenCentral()
}
 

dependencyManagement {
    dependencies {
        dependency group: 'com.google.cloud', name: 'spring-cloud-gcp-dependencies', version: '4.1.4', type: "pom", scope: "import"
    }
}
dependencyManagement {
    imports {
        mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:4.1.4"
    }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}
dependencies {
    implementation 'com.google.cloud:spring-cloud-gcp-starter-sql-mysql'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.mysql:mysql-connector-j'
 
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

How can I create the container image and push it to the Artifact Registry? Should I add something to my build.gradle file? or should I run the command in another way?


Solution

  • Obviously, your Gradle usage is wrong, and you didn't even seem to have set up Jib. I suggest you follow the Jib Quickstart guide.