I want to be able to import org.springframework.retry:spring-retry:1.3.2-SNAPSHOT using Gradle.
However, spring-retry dependency (of different version): org.springframework.retry:spring-retry:1.2.5.RELEASE is coming from org.springframework.boot:spring-boot-starter-integration -> 2.3.3.RELEASE.
How can I exclude the dependency coming from spring-boot-starter-integration and rather import 1.3.2-SNAPSHOT version?
Here is the link to my Gradle: https://github.com/Nikhilgupta1891/RetryRecover/blob/main/build.gradle%20copy#L55
Explicitly add
implementation 'org.springframework.retry:spring-retry:1.3.2-SNAPSHOT
and add
https://repo.spring.io/snapshot
to the repositories.
However, it's not been published with recent changes yet, you will need to build it locally and mvn clean install and add mavenLocal() to the repos.
Related
I have a gradle project with several modules in it. In the main module I have id "io.spring.dependency-management" plugin. In the adapters module I have dependency on the main one implementation project(":main") with runtimeOnly 'io.r2dbc:r2dbc-postgresql in dependency block, which pulls 0.8.12.RELEASE version of the r2dc-postgresql driver.
Now I want to use 0.8.13.RELEASE verision of the driver, so I simply added runtimeOnly 'io.r2dbc:r2dbc-postgresql:0.8.13.RELEASE to the dependency declaration, but now I have two versions of this library in external libraries section (0.8.12.RELEASE and 0.8.13.RELEASE), but ./gradlew adapters:dependencies displays only 0.8.13.RELEASE version.
How to find out where 0.8.12.RELEASE is coming from now and remove it?
I tried
exlude(group = 'io.r2dbc', module = 'r2dbc-postgresql')
but it didn't work
have you had a look at e.g.:
https://docs.gradle.org/current/userguide/resolution_rules.html
or
How to exclude library from all dependencies in Kotlin DSL build.gradle?
or
What does this "all*.exclude" means in Gradle transitive dependency?
I have some code which needs access to org.springframework.util.MultiValueMap.
I am running IntelliJ IDEA on a Windows machine. I am getting a compilation error:
"Cannot access org.springframework.util.MultiValueMap".
This error occurs on the following line of code (request is an object of type ClientHttpRequest), which is in a junit test file:
String authorization = request.getHeaders().getFirst("Authorization");
I have tried the following two import statements, based on the documentation for MultiValueMap (https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/MultiValueMap.html):
import org.springframework.util;
import org.springframework.util.MultiValueMap;
However these do not work - latter parts of those statements are highlighted in red. I believe this is because I don't have the correct dependencies in build.gradle.
These are the Spring Framework dependencies I currently have:
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.ws:spring-ws-core")
compile('org.springframework.security:spring-security-web:5.0.2.BUILD-SNAPSHOT')
compile('org.springframework.security:spring-security-config:5.0.2.BUILD-SNAPSHOT')
compile('org.springframework.security:spring-security-config:5.0.2.BUILD-SNAPSHOT')
compile("org.springframework.security.oauth:spring-security-oauth2:2.0.8.RELEASE")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.ws:spring-ws-test')
I have found a fix!
The answer was on this page here: https://spring.io/blog/2015/02/23/better-dependency-management-for-gradle
It appears that using gradle for dependency management for Spring-Boot can be problematic because you need so many lines in your dependencies section, like the ones I listed above.
I followed the instructions on that page, inserting the following lines into my build.gradle:
apply plugin: "io.spring.dependency-management"
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.1.1.RELEASE'
}
}
My code now compiles. I still don't know where I would have been able to find the correct individual dependency for build.gradle, but using this plugin it is no longer an issue.
You may be doing a bit too much work here. Alternatively, you run the risk of having your dependencies slightly out-of-sync.
The only dependency you need is spring-boot-starter, which has a transitive dependency to the correct spring-core version you want.
You can use this in your build.gradle file:
compile'org.springframework.boot:spring-boot-starter:1.5.10.RELEASE'
If you want to use the Gradle plugin for Spring Boot (which can be found here), place the version of Spring Boot you want into the plugin section and omit the versions on your dependencies.
This line would go at the top of your class
import org.springframework.util.MultiValueMap;
And while I'm not necessarily familiar with this exact library, looking on mvnrepository tells me that you would need something like this in your build.gradle file
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework', name: 'spring-core', version: '5.0.3.RELEASE'
}
There is a library that I would like to use for my Android App: ez Vcard. However this library uses Maven, which I'm not familiar with. I checked online and my Import Project objection doesn't offer pom.xml soo, how can I add the dependency
<dependency>
<groupId>com.googlecode.ez-vcard</groupId>
<artifactId>ez-vcard</artifactId>
<version>0.9.9</version>
</dependency>
into my project and specifically where?
You don't need a maven project, you can use maven dependencies in gradle projects, you'll just have to use a gradle format of the dependency.
This library appears to be hosted on maven central, so you have to link to this repository host in your global build.gradle:
allprojects {
repositories {
mavenCentral()
}
}
To import this dependency into your project, in your module-local build.gradle file input the following lines:
dependencies {
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.9'
// all the other dependencies...
}
You can actually see here all the different dependency formats (under 'Dependency Information'), from maven to gradle, ivy, sbt and so on, they are all compatible with the repository.
I am trying to include LazyBones, which is stored here in Bintray/JCenter in my Gradle project as a compile-time dependency, like so:
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
compile 'com.typesafe.akka:akka-actor_2.10:2.3.12'
compile 'org.codemonkey.simplejavamail:simple-java-mail:2.3'
compile 'pledbrook/lazybones-templates:lazybones:0.8.1' // <-- here
}
I have tried many other combination/permutations of group/artifact names for the 0.8.1 version, but nothing is working/resolving. This is the first time I’ve ever (intentionally) tried depending on a compile binary that is only stored in JCenter, and not available via Maven Central. So I ask: what’s the difference between Maven Central and JCenter coordinates, and what do I need to do so that Gradle can “find” the LazyBones JAR living in JCenter?
The thing with this Lazybones artifact is that it's not a maven artifact. It's a zip, not in maven layout, and from what I know about Lazybones it's not supposed to be used directly as a dependency from Gradle/Maven.
That's why you can't use the normal coordinates.
What would be the easiest way to tell Gradle the following:
Retrieve 'junit' dependency and take its latest 'release' version.
Managing Maven and Ivy repositories is sort of new to me. I tried the following steps and they result in Could not resolve dependency ... error:
Write compile "junit:junit:latest.release" with repositories set to only mavenCentral() (however, it works if I say "junit:junit:4.10").
Write compile "junit:junit:latest.release" with repository set the following way:
ivy {
// I also tried 'http://maven.org' and other possible variants.
url "http://repo1.maven.org"
layout "maven"
}
Attempted to use Spring Source Ivy repository:
ivy {
artifactPattern "http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
ivyPattern "http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
}
Maybe I misunderstand something. Why would getting the latest version of the dependency be such a hard task?
It can be quite useful sometimes to get the latest release - if for example you release often your own dependencies.
You can get the latest version like
compile "junit:junit:+"
or better specify at least the major version like
compile "junit:junit:4.+"
Gradle currently does not support Maven's RELEASE (which is rarely used and deprecated) but it does support Ivy's latest.release (and for snapshots latest.integration). However, the general recommendation is to build against exact versions. Otherwise, the build can become a lottery.
Check out the Gradle-Versions-Plugin. It does exactly what you want: https://github.com/ben-manes/gradle-versions-plugin
For the installation, see the github page. Basically you need to add these two lines to your build.gradle - project file:
apply plugin: 'com.github.ben-manes.versions'
buildscript {
[...]
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.8'
[...]
}
}
[...]
Then you can use the plugin, by running this command in terminal in your project dir:
./gradlew dependencyUpdates -Drevision=release
And it will show you which dependencies are outdated!
Latest Gradle User Guide mentions and explains plus sign in versions:
From 7.2. Declaring your dependencies:
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
... The build script also states that any junit >= 4.0 is required to compile the project's tests.
From 23.7. How dependency resolution works:
If the dependency is declared as a dynamic version (like 1.+), Gradle will resolve this to the newest available static version (like 1.2) in the repository. For Maven repositories, this is done using the maven-metadata.xml file, while for Ivy repositories this is done by directory listing.
In Android Studio:
If you're using + for the version, and want to know which version is actually being used, select Project in the sidebar, and then under External Libraries you will see the actual version number in use.
Another similar notation for Kotlin DSL (build.gradle.kts):
dependencies {
implementation("or.jsoup", "jsoup") {
version {
require("1.14.+")
}
}
// OR simply
// implementation("or.jsoup:jsoup:1.14.+")
}
Read more about this in Gradle documentations.
An excerpt from the docs:
A dynamic version can be either a version range (e.g. 2.+) or it can be a placeholder for the latest version available e.g. latest.integration.