Gradle cannot find Spring Boot 3.0.0-M1 - spring

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.

Related

gradle does not fetch dependencies after upgrade from 5.1.1 to 6.4.1

I have several services that uses gradle 5.1.1 with java 8.
As we want to upgrade to Java 13, we first need to upgrade to gradle 6after doing so, some dependencies are not fetched.
Those dependencies are listed with compile() under a dependency which is our jar library and still built with gradle 5.1.1
our libraries are stored in a S3 bucket and we use shadowjar to generate the end jar.
so, for example:
I have project A which I want to upgrdae.
Project A has project B as a dependency (compile)
Project B has google guava as a dependency (also with compile)
Now, project A, that under gradle 5.1.1 had fetched guava with no problems, alerting me that it is missing guava after upgrading to gradle 6.
I use local computer installed gradle (not wrapper).
Here are the important build.gradle parts:
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
ext.ver = [
'springboot': '2.2.0.RELEASE',
'slf4j' : '1.7.12'
]
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${ver.springboot}"
classpath 'io.spring.gradle:dependency-management-plugin:1.0.7.BUILD-SNAPSHOT'
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
classpath 'com.amazonaws:aws-java-sdk-core:1.11.5'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
}
configurations {
compile.exclude module: 'spring-boot-starter-logging'
testCompile.exclude module: 'spring-boot-starter-logging'
runtime.exclude module: 'spring-boot-starter-logging'
compile.exclude group: 'ch.qos.logback'
}
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 10, 'seconds'
resolutionStrategy.cacheChangingModulesFor 10, 'seconds'
}
dependencyManagement {
applyMavenExclusions = false
}
repositories {
mavenLocal()
maven {
url "s3://bucket"
credentials(AwsCredentials) {
accessKey = awsCredentials.AWSAccessKeyId
secretKey = awsCredentials.AWSSecretKey
}
metadataSources {
artifact()
}
}
mavenCentral()
}
dependencies {
compile("com.test:projectB:1.0.0")
...
}
import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer
shadowJar {
classifier = ''
baseName = 'project-A'
manifest {
attributes 'Main-Class': 'com.test.projectA.Starter'
}
mergeServiceFiles()
append 'META-INF/spring.handlers'
append 'META-INF/spring.schemas'
append 'META-INF/spring.tooling'
transform(PropertiesFileTransformer) {
paths = ['META-INF/spring.factories']
mergeStrategy = "append"
}
}
Could this be because project B was not built with new gradle?
unfortunately, I cannot create a real reproducer as those libraries are real code of the company I work at.
Thanks and Regards,
Ido
The metadataSources declaration of the s3 bucket Maven repository is most likely the root cause why transitive dependencies of projectB are not resolved. The documentation is quite a bit vague here, but I suspect artifact() looks for the actual jar file only and not for the POM file, hence transitive dependency resolution is not performed. You should be able to see this behavior when running the build with switches --info and --refresh-dependencies.
Thankfully, this is quite easy to fix. Add mavenPom() and Gradle will try to resolve the POM first and with that, dependency resolution should be back to normal.
And while you're at it, you might want to read the upgrading from Gradle 5 guide and get rid of the compile configuration in favor of implementation. You should be able to see a warning similar to this when running the build with --warning-mode all:
The compile configuration has been deprecated for dependency declaration. This will fail with an error in Gradle 7.0. Please use the implementation or api configuration instead. Consult the upgrading guide for further information: https://docs.gradle.org/6.4.1/userguide/upgrading_version_5.html#dependencies_should_no_longer_be_declared_using_the_compile_and_runtime_configurations

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

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

Gradle dependency management plugin

I am trying to run the following minimal gradle build file including the dependency management plugin:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
But then running gradle fails:
* What went wrong:
Plugin [id: 'io.spring.dependency-management', version: '1.0.4.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 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.4.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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warnings
Is there a missing dependency in the gradle file?
The plugin cannot be found because you defined repositories inside your build script and tried to use plugin outside it. Remove buildscript or add repositories for your build file also.
(Dependencies and repositories defined inside build script are accessible in that buildscript scope)
Example:
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}

Gradle Spring Boot - spring jar versions are not automatically picked up

I am trying out a simple gradle spring boot application as per the below URL
https://spring.io/guides/gs/spring-boot/
This is my build.gradle file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'my-jar'
version = '1.0.0'
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
testCompile "junit:junit"
}
I am using a local artifactory and my init.gradle has the buildscript configuration which is below
buildscript {
repositories {
maven {
url 'http://mylocalartifactory:8081/'
}
}
dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE" }
}
I get the below error when i try to run gradlew build
What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter-web:.
Looks like the version is not getting applied for the dependency.
What I understand is that the version will be defaulted by the spring-boot plugin .
Am I missing something ?
It works fine if I mention the version number in the dependency
dependencies {
compile "org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE"
testCompile "junit:junit"
}
Though I can make it work , it beats the purpose of using spring boot if I need to manually specify the spring version jar dependency .
Kindly revert back if you see any issue in my build.gradle or init.gradle

How do I run spring-boot 1.2.x executable jar

This is a continuation of another question that got partially answered. Since the question morphed, I thought I should open a question that is more inline with that.
I have a project that started out as a spring-boot 1.1.7.RELEASE and I started from a directory containing the jar and an application.properties file via:
java -jar edm-0.1.0.jar
Everything was right as rain until I upgraded to spring-boot 1.2.1.RELEASE. Now, when I try to start with java -jar the app appears to start but trying to login gives me an error that the /templates html pages aren't found.
It would appear that the preferred way to start spring-boot apps is:
gradle bootRun
This would appear to work as long as I am in the top level of my project directory. But if I move the jar file off to another directory, and try to run it, I get the error:
:temp$ gradle bootRun
FAILURE: Build failed with an exception.
* What went wrong:
Task 'bootRun' not found in root project 'temp'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
so when I run "gradle tasks" I can see that "bootRun" is not available:
:temp$ gradle tasks
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
dependencies - Displays all dependencies declared in root project 'temp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'temp'.
help - Displays a help message
projects - Displays the sub-projects of root project 'temp'.
properties - Displays the properties of root project 'temp'.
tasks - Displays the tasks runnable from root project 'temp'.
I guess this is a spring-boot gradle issue, but I can't say for sure. My version:
:temp$ gradle -version
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
Build time: 2013-12-17 09:28:15 UTC
Build number: none
Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.8.0_31 (Oracle Corporation 25.31-b07)
OS: Mac OS X 10.10.2 x86_64
And here is my build.gradle:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.8'
languageLevel = '1.8'
}
}
jacoco {
toolVersion = "0.7.0.201403182114"
}
project.ext {
springBootVersion = '1.2.1.RELEASE'
}
configurations {
querydslapt
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
}
}
jar {
baseName = 'edm'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/snapshot" }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile('com.android.tools.build:gradle:1.0.1')
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
I did read the documentation, but nothing seems to address why I am having this problem. I would really appreciate any help you can send my way.

Resources