Only pom.xml retrieved from maven dependency in gradle spring boot project - gradle

This is for sure a duplicate question, but I am not understanding what's happening.
I am trying to use the apicurio-registry library.
I added the following line in my build.gradle file :
implementation group: 'io.apicurio', name: 'apicurio-registry', version: '1.3.1.Final', ext: 'pom'
After building, I can see that I only retrieved the pom.xml, but not any of the jars specified in it (There is nothing except the pom.xml in the gradle caches).

Related

reactor.netty error when depending on spring-boot-starter-webflux

I have a java project based on Spring framework, which is based on gradle build tool.
The gradle configures a parent project Par and sub-project Child.
The Par project has the build.gradle setting spring framework boot version as 2.2.6:
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
...
}
The Child project has the build.gradle as below:
ext.versions = [
spring: '5.2.9.RELEASE',
spring_boot: '2.2.10.RELEASE',
slf4j: '1.7.30',
grpc_helpers_java: '^19.0'
]
I tried to use WebClient of spring framework, so I added spring-boot-starter-webflux dependency to the build.gradle file of the child project as below:
dependencies {
...
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: versions.spring_boot
...
}
I don't have other code change yet.
However, although the build passed, the bootRun from the Par project failed with the following error:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory.createHttpServer(NettyReactiveWebServerFactory.java:163)
The following method did not exist:
'reactor.netty.transport.Transport reactor.netty.http.server.HttpServer.runOn(reactor.netty.resources.LoopResources)'
The method's class, reactor.netty.http.server.HttpServer, is available from the following locations:
jar:file:/C:/Users/XXX/.gradle/caches/modules-2/files-2.1/io.projectreactor.netty/reactor-netty/0.9.12.RELEASE/41022546d07f1499fb9d8617bba4a1a89d3549db/reactor-netty-0.9.12.RELEASE.jar!/reactor/netty/http/server/HttpServer.class
The class hierarchy was loaded from the following locations:
reactor.netty.http.server.HttpServer: file:/C:/Users/XXX/.gradle/caches/modules-2/files-2.1/io.projectreactor.netty/reactor-netty/0.9.12.RELEASE/41022546d07f1499fb9d8617bba4a1a89d3549db/reactor-netty-0.9.12.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.http.server.HttpServer
I think the transitive dependency reactor.netty has a version of 0.9.12 is correct based on the spring-boot-starter-webflux version of 2.2.10. So I do not understand why the bootRun is trying to look for reactor.netty.http.server.HttpServer.runOn method which doesn't exist for reactor.netty version 0.9.12
Thank you very much.

spring boot plugin and gradle dependency implementation

We have been using gradle spring boot plugin version 1.5.14 and gradle 4.10.3 for our builds. After an upgrade of gradle to 6.2.2, we've also changed dependency-definition from compile group to implementation group i.e.:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-integration'
to
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-integration'.
The fat jar created via gradle assemble does to my surprise not contain the required libs under BOOT-INF/lib anymore? If I replace "implementation" with "compile" it works again as expected.
Is there something which needs to be configured so that spring-boot-plugin adds them? Or do I need to upgrade the project to spring boot 2 beforehand?
Implementation will bring in the dependency only for that module it is declared in.
Compile will allow a module that depends on the module to use the dependency as well.
Say you have Module A depending on Module B.
Module A and B both need the dependency:
com.font:font1:1.1.1
If B uses:
implementation 'com.font:font1:1.1.1'
A will not see font1, and will need to bring it into its own build.gradle file as well.
compile 'com.font:font1:1.1.1'
will make it available to the entire classpath (which should be avoided anyway, and the new equivalent is for libraries which uses 'api' instead of 'compile').
Without seeing your project directory, I'm assuming that some dependency is not being pulled into a place where it used to be grabbed from a lower dependency in the hierarchy. You should be able to find the missing dependencies easily by changing compile to implementation one at a time, unless you have a huge multi-module project.

when downloading a dependency jar, how to make its dependencies get downloaded

I have built two jars and put them in Artifactory. One of the jars depends on the other (the dependency is in its build.gradle file). When I download the main jar as a dependency of my main app, the dependent jar is not downloaded. The only way I can get both is to put two compile statements in the build.gradle. How do I cause the dependent jar to also get downloaded?
The main jar file is user-cache.jar and it depends on blue-redis.jar. The build.gradle in the app that uses my main jar uses this compile statement:
compile(group: 'etd.user-cache', name: 'user-cache', version: '1.0.2', ext: '12.SNAPSHOT.jar')
The build.gradle for user-cache has this in it:
compile(group: 'etd.blue-redis', name: 'blue-redis', version: '1.0.1', ext: '4.SNAPSHOT.jar')
When I build my app, it only gets user-cache.jar. That makes it necessary to put both compile statements in my app's build.jar
What should I do to cause the blue-redis.jar to also be downloaded without needing its compile statement?
I assume that you are using a maven repository in Artifactory. When gradle is doing dependency resolution it will attempt to download a POM file and check for transitive dependencies as well as parent poms which may list additional dependencies.
To get the desired behavior, when you publish the main jar to Artifactory you need to include in its POM file a dependency on the other JAR.

Gradle does not download complete dependencies

Im trying to download and build spring-data-hadoop 2.4.0.RELEASE using the following decleration in my dependencies.gradle:
dependencies {
...
// compile('org.springframework.data:spring-data_hadoop:2.4.0.RELEASE')
compile group: 'org.springframework.data', name: 'spring-data-hadoop', version: '2.4.0.RELEASE'
...
}
Refreshing gradle now results in downloading the newly added dependency BUT the data is not consistend. I got the following external dependencies after the download:
I thought everything is fine now... but I am wrong. Lets open up one of those and look depper into the packages:
If you compare the content of org.springframework.data.hadoop.config with the official API you will notice, that in this package, there should be much more content. The annotations package for example.
How can it be that gradle is not downloading the complete source?
There is a separate spring-data-hadoop-config with the description "Spring for Apache Hadoop Annotation Configuration", so that's probably where annotations would be.
You are pulling the main jar that should pull the transitive artifacts as well.
the org.springframework.data.hadoop.config.annotation is included inside
compile group: 'org.springframework.data', name: 'spring-data-hadoop-config', version: '2.4.0.RELEASE'

Gradle dependency management using pom.xml

In build.gradle we specify the dependencies as
compile group: 'org.apache.pig', name: 'pigunit', version: '0.11.0-cdh4.5.0', transitive: true
Running gradle cleanEclipse eclipse sets up the projects(adds the jar to classpath)
However there are only maven dependencies available for some APIs
(I am trying to run jersey 2.x examples bundle from https://jersey.java.net/download.html and it provides only pom.xml)
EDIT:
I know i can specify
compile group: 'groupId', name: 'artifactId', version: 'version' gradle but doing it manually for all dependencies or writing a program to do so should not be natural gradle way.
Gradle provides a maven plugin http://gradle.org/docs/current/userguide/maven_plugin.html.I haven't tried it out but it should be able to do it
Gradle supports Maven dependencies. Just specify the dependencies in the same way as your example:
compile group: 'groupId', name: 'artifactId', version: 'version'
To lookup the the artifact coordinates, you can use sites like http://search.maven.org
The only thing you have to make sure is to include either your internal Maven repository (if you are in a company which has one) or Maven Central:
repositories {
mavenCentral()
}
or
repositories {
maven {
url "http://repo.mycompany.com/maven2"
}
}

Resources