could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.6.RELEASE' - spring-boot

Gradle command throwing below Exception:
FAILURE: Build failed with an exception.
Where:
Build file '/Users/abel/Desktop/work/gundam/build.gradle' line: 2
What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.1.6.RELEASE'] 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.1.6.RELEASE')
Searched in the following repositories:
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 5s
Configuration:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

You should upgrade the gradle version and currently upgrade to Gradle 5.5.1 is ok,
and you need to set your idea to the current update gradle version
https://plugins.gradle.org/plugin/org.springframework.boot

It is because of network problem, when I change the vpn , it started working

Related

Getting SpringBoot error - Execution failed for task ':compileJava

The below is my build.gradle.
When I Bootrun, i get the error
Execution failed for task ':compileJava
invalid source release: 18
plugins {
id 'org.springframework.boot' version '2.6.9'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.loginapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '18'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Since you're using IntelliJ, shared the screenshot and told us you alread checked the java version and I already got this error a few times here is my TODO I go through when I get this error:
Do what you showed us on the screenshot (Check Project Version and language level)
Do the same for Modules (Project Structure > Modules) Don't forget the Dependencies Tab there you can find the module SDK
Check Java Compiler (Settings > Build, Execution, Deployment > Compiler > Java Compiler) there you can see a Project bytecode version & Per-module bytecode version -> Check those
Hope this works :)

Gradle cannot find Spring Boot 3.0.0-M1

I'm not sure how to debug this or what is wrong at all. I am trying to run this project: https://github.com/spring-projects/spring-security-samples/tree/main/servlet/spring-boot/java/jwt/login
In the project, Spring Boot 3.0.0-M1 is used to show the latest possibilities of JWT authentication. However, my Gradle cannot find this Spring Boot version no matter what I do. When I set it to 2.6.6 it works again, but it doesn't seem to be able to find 3.0.0-M1.
When I try to sync the dependencies I get the following error:
Build file 'C:\my files\general\subjects\programming\Open-source\spring-security-samples\servlet\spring-boot\java\jwt\login\build.gradle' line: 2
Plugin [id: 'org.springframework.boot', version: '3.0.0-M1'] was not found in any of the following sources:
* 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.
The Gradle configuration is as follows:
plugins {
id 'org.springframework.boot' version '3.0.0-M1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
outputs.upToDateWhen { false }
}
I was able to fix it by downloading a 3.0.0-M2 project from Spring Initializr and seeing what differs between the example I got from the Spring Security examples repository and the generated project from Spring Initializr.
It turns out that adding the following to settings.gradle fixes it:
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
}
I am not sure why the example project didn't have this already.

Could not find org.springframework.boot:spring-boot-dependencies:2.6.1

I follow the instructions here for the latest spring.framework.boot plugin.
My build.gradle has
plugins {
id 'java-library'
id 'eclipse'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '2.6.2'
id 'org.springframework.boot.experimental.thin-launcher' version '1.0.23.RELEASE'
}
but gradle tasks have the error
> Could not resolve all dependencies for configuration ':detachedConfiguration1'.
> Could not find org.springframework.boot:spring-boot-dependencies:2.6.2.
UPDATE I neglected to add the final lines of the error description, which were in fact important to answer it.
Searched in the following locations:
- https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-dependencies/2.6.2/spring-boot-dependencies-2.6.2.pom
- https://repo.spring.io/milestone/org/springframework/boot/spring-boot-dependencies/2.6.2/spring-boot-dependencies-2.6.2.pom
Here is a FULL file as an example: (this is the ROOT build.gradle) (If you code a monolith, you'll only have a root build.gradle, if you write multiple "gradle modules", you'll have a root and subproject build.gradle files) (if you have no idea what i'm talking about see link to docs.gradle.org at bottom)
(you can remove the dependencies, but i prefer to give a full working)
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-batch'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'com.h2database:h2'
implementation 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.batch:spring-batch-test'
testImplementation 'org.springframework.integration:spring-integration-test'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
allprojects {
/* custom task to show dependencies. run "gradle printAllDependencies" from commandline. see https://stackoverflow.com/questions/44266687/how-to-print-out-all-dependencies-in-a-gradle-multi-project-build/54436979#54436979 */
task printAllDependencies(type: DependencyReportTask) {}
}
Alternatively, you can try a "gradle FLUSH"
Gradle FLUSH Cache
(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.
./gradlew --stop
OR
gradle --stop
(now delete the folders)
rm -rf $HOME/.gradle/caches/
rm -rf $HOME/.gradle/build-cache-tmp/
(now resume normal gradlew commands like:)
./gradlew clean build
and alternatively, you can do an intelliJ "FLUSH"
(tested with IntelliJ version 2020.1 or later)
Close IntelliJ.
Delete the ".idea" folder off of the root folder.
Re OPEN the project.
Wait for Gradle imports and indices rebuild to complete
Try the IDE build again.
And the big hammer: "Invalidate IntelliJ caches". see https://www.jetbrains.com/help/rider/Cleaning_System_Cache.html and/or https://www.jetbrains.com/help/idea/invalidate-caches.html
If you're using Eclipse or NetBeans or Other, you'll have to find the "equivalent". The idea is that the IDE gets "confused".
BONUS
Multi Gradle Module :
https://docs.gradle.org/current/samples/sample_building_java_applications_multi_project.html
Thanks to #granadaCoder above, and after reinstalling Gradle to the latest version 7.3.3 the actual problem was that a 2nd repositories setting had crept into my build.gradle
repositories {
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
Which was exactly where the error said the dependencies were not found. I changed this to
repositories {
mavenCentral()
}
Things then started to work.

Could not find method annotationProcessor() for arguments

Following is my build.gradle file. My project compiles locally (IntelliJ-IDEA is my IDE), but when I push it to GitHub, the travis-ci build fails. My gradle version is gradle-5.2.
apply plugin: "java"
apply plugin: 'jacoco'
sourceCompatibility = 1.8
version = "1.0"
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.2'
compileOnly 'org.projectlombok:lombok:1.18.2'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.2'
testCompileOnly 'org.projectlombok:lombok:1.18.2'
}
FAILURE: Build failed with an exception.
Where: Build file '/home/travis/build/XXX/PROJECT/build.gradle' line: 33
What went wrong: A problem occurred evaluating root project 'PROJECT'.
Could not find method annotationProcessor() for arguments [org.projectlombok:lombok:1.18.2] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
The annotationProcessor in build.gradle seems not to be parsed, I'm not sure what the underlying issue is. Any help would be appreciated. Thanks.
As #M.Ricciuti said, the annotationProcessor is available from gradle versions 4.6 and later. So what we should do is just confirm that gradle's version >= 4.6. We'd be better off using the Wrapper.Thanks, that's all.
A ery easy way to update the gradle version of your project in intellij is to go to inside your project, gradle, wrapper, gradle-wrapper.properties and update the version in the line below:
disributionUrl=https://services.gradle.org/distributions/gradle-4.6-bin.zip

Gradle 4.7 build throw error executing task bootRepackage

While executing gradle build command in my existing spring boot project which was / is building fine with older version of Gradle (For ex: 3.4.*).
But after I upgraded Gradle to latest version (4.7) using SDK, its started throw error while building.
Config List:
------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------
Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_121 (Oracle Corporation 25.121-b13)
OS: Linux 3.16.0-4-amd64 amd64
Spring Boot Details:
springBootVersion = '1.5.1.RELEASE'
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
build.gradle Note: I can't publish whole build file. So giving some import lines to analyse.
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}"
}
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'war'
apply plugin: 'org.sonarqube'
// make sure bootRepackage is included in task graph
project.tasks.findAll { it.name.startsWith("artifactory") } .each { it.dependsOn assemble }
// so we can maintain both "normal" and "boot" jars
springBoot {
classifier = 'boot'
}
publishing {
publications {
mavenJava(MavenPublication) {
// from components.java
// "boot" jar
artifact ("$buildDir/libs/${project.name}-${version}-boot.war") {
classifier = 'boot'
}
}
}
}
def profiles = 'development'
bootRun {
args = [
"--spring.profiles.active=" + profiles
]
}
defaultTasks 'bootRun'
// Other tasks and dependency list
}
Output from Command Line:
gradle build
Task :test-service:bootRepackage FAILED
> FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings
Spring Boot 1.5.x only supports Gradle 2 (2.9 or later) and Gradle 3. Gradle 4 is not supported.
You could either stick with Gradle 3.x or upgrade to Spring Boot 2.0.x which does support Gradle 4.
The error clearly states that -
* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class
Please check if you have entry similar in your build.gradle
apply plugin: 'application'
mainClassName = 'com.my.MyApplication' // your application main class goes here
According to this question, you have to set the main class :
bootRepackage {
mainClass = 'your.app.MainClass'
}

Resources