GitLab CI: Spring Boot Gradle Plugin not found!

The log describing the failure:

Running with gitlab-runner 14.4.0 (v14.4.0)
  on ikarus10 1d6a24ce
  feature flags: FF_NETWORK_PER_BUILD:true
Preparing the "docker" executor
00:05
Using Docker executor with image gradle:alpine ...
Authenticating with credentials from /var/lib/gitlab-runner/.docker/config.json
Pulling docker image gradle:alpine ...
Using docker image sha256:9eb6f8808028380d114ca5f6cac22ec9ff5bcd885b59756d1fae9afa61fd3d7b for gradle:alpine with digest gradle@sha256:769db4d30a935c368cdd42757fd8dae06aebaf8998c28dc1583d55d1cb495986 ...
Preparing environment
00:01
Running on runner-1d6a24ce-project-200746-concurrent-0 via ikarus10...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/Shift2Rail_TMS/dev/s2r-cg-cloud/gitlab-ci-spring-boot-demo/.git/
Created fresh repository.
Checking out 1d8d35c7 as main...
Skipping Git submodules setup
Restoring cache
00:00
Not downloading cache main due to policy
Executing "step_script" stage of the job script
03:53
Using docker image sha256:9eb6f8808028380d114ca5f6cac22ec9ff5bcd885b59756d1fae9afa61fd3d7b for gradle:alpine with digest gradle@sha256:769db4d30a935c368cdd42757fd8dae06aebaf8998c28dc1583d55d1cb495986 ...
$ export GRADLE_USER_HOME=`pwd`/.gradle
$ gradle --build-cache assemble
Welcome to Gradle 7.2!
Here are the highlights of this release:
 - Toolchain support for Scala
 - More cache hits when Java source files have platform-specific line endings
 - More resilient remote HTTP build cache behavior
For more details see https://docs.gradle.org/7.2/release-notes.html
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.2/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build 
FAILURE: Build failed with an exception.
* Where:
Build file '/builds/Shift2Rail_TMS/dev/s2r-cg-cloud/gitlab-ci-spring-boot-demo/build.gradle' line: 2
* What went wrong:
**Plugin [id: 'org.springframework.boot', version: '2.5.6'] was not found in any of the following sources:**
**- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)**
**- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.5.6')**
**  Searched in the following repositories:**
**    maven(https://plugins.gradle.org/m2/)**
**    Gradle Central Plugin Repository**
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3m 19s
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

The settings.gradle:

pluginManagement {
  plugins {
  }
  resolutionStrategy {
  }
  repositories {
      maven { url "https://plugins.gradle.org/m2/" }
      gradlePluginPortal()
  }
}

rootProject.name = 'gitlab-ci-spring-boot-demo'

The build.gradle:

plugins {
	id 'org.springframework.boot' version '2.5.6'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}

group = 'example.com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
	useJUnitPlatform()
}

The .gitlab-ci.yml file:

image: gradle:alpine

# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle

build:
  stage: build
  script: gradle --build-cache assemble
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: push
    paths:
      - build
      - .gradle

test:
  stage: test
  script: gradle check
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: pull
    paths:
      - build
      - .gradle

It is working on my local laptop!

I also checked the repository under that link: https://plugins.gradle.org/m2/.

Problem solved:

  • Gradle Proxy Settings were missing to get access to Central Maven Repository:
  1. Added a gradle.properties with the correct proxy settings to the root directory of project.
  2. Added necessary proxy settings to .gitlab-ci.yml:
    variables:
    GRADLE_OPTS: “-Dorg.gradle.daemon=false”
    http_proxy: $CODE_PROXY
    ** https_proxy: $CODE_PROXY**
    ** no_proxy: 127.0.0.1,localhost,…**
    ** NO_PROXY: 127.0.0.1,localhost,…**