How to add exclutions to dependencies on maven - maven

I have the following dependencies that unfortunately requires some classes which are not present on the default packages. First it is 'spring-cloud-starter-sleuth', when I add the local maven jar updated to version 3.1.5 it requires 'brave-context-slf4j' version 5.14.1 and I have added them without problems.
The problem is the standard dependencies which includes those jars e.g 'spring-cloud-dependencies' should exclude the other versions so this way I can use only spring-cloud-starter-sleuth:3.1.5 and brave-context-slf4j:5.14.1.
How could I add those exclusions to that dependencies?

Related

How does Gradle auto updates versions for dependencies?

In my build.gradle , for one of the direct dependency A , "jersey-client" 2.25.1 is transitive dependency. But when I do gradle build it downloads 2.7 version, when I check dependency A pom, it has only 2.25.1 version, how Gradle resolves it to 2.7?
There are versions above 2.7 as well in the artifactory, how only 2.7 is downloaded?
Only dependency A is using jersey-client.
Cleared gradle cache and tried, but same result.
There's probably another dependency in your dependency graph bringing in a later version. Try running
gradle dependencies
And it should show some insight into why it chose the newer version. Gradle has a few strategies allowing you to force a particular version of a dependency or perhaps ignoring transitive dependencies of a particular dependency should you wish to do so
Spring dependency management plugin is overriding jersey 2.25.1 with 2.7,
I have explicitly declared in my build.gradle file to use 2.25.1 by adding the below property.
ext['jersey.version'] = '2.25.1'

How to recompile gradle dependency from sources?

We have a dependency dep which was originally compiled in Java 8. The project requiring this dependency is compiled and run with Java 6. This results ``bad major version'' error.
We have the sources available in our central repository for dep and looking for a way that the sources are downloaded in build.gradle:
compile('dep_group:dep_artifact:version:sources')
and then recompile in JDK 6 to produce the required jar file.
Is it possible? Or any suggestions?
Alternatively, we have to download the code of dep offline, recompile with JDK 6, publish the jar file and finally add it as a dependency. But we are looking to avoid this long route. This is just for testing purposes and we do not want to publish a new version compiled with an older version of Java.
Without original build file (POM / build.gradle / ant.xml) you cannot recompile library. If it is a rather simple library - possible option is to include its sources as additional module in multi-module Gradle project:
Download sources
Create folder for them in your project
Create additional module as described in Gradle docs: https://docs.gradle.org/current/userguide/multi_project_builds.html
Apply java plugin for module
Set dependency on this project in format: compile(project(':dep'))
Finally, when you build your project Gradle will compile this module and use it as dependency for your main module.
Do not forget to check library license, e.g. Apache License 2 permits such a simple usage of sources.

How install Swagger without Maven

I am not MavenĀ“s user and i want configure all dependencies of Swagger in my project. I try make it unsucessful. I get thousands jars, jackson-, swagger- and nothing.
From https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X#adding-the-dependencies-to-your-application:
Projects that cannot utilize maven's dependencies would need to add
the dependencies manually. Since those may change from version to
version, the list of dependencies will not be documented here.
Instead, it is advised that you clone the swagger-core repository, go
to the directory of the relevant module (artifact) and run mvn dependency:list. That would give you a list of dependencies required
by swagger-core which you would have to include manually in your
application. Keep in mind this requires you to have maven installed
but it does not require you to use maven for your project.

What is the purpose of providing a downloaded pom.xml on mvnrepository.com

On mvnrepositry, when you search for a certain module, there's a link to download the binary. For some versions it has a pom.xml file available for download instead of the jar. What are you supposed to do with that pom.xml? It seems like if I specify a version that does not have a downloadable jar, but instead downloadable pom.xml, my maven build will fail. Is what I'm seeing correct?
Modules that only have pom files are maven modules with pom packaging. They are used to aggregate multiple modules into one unit. You can use such a module as a dependency for your maven project. Maven will download the pom file, analyze the dependencies included in that pom file and download those & add it to your automatically.
Even modules that have jars (jar packaging) have a pom file associated with them. This pom file defines the other dependencies that are required for using it. Maven will automatically process and fetch those dependencies (transitive dependencies).
This makes specifying and managing dependency for any project. You will specify the top level modules that your projects directly depends on and other things required will automatically figured out and downloaded. It also makes it easier when you have upgrade to a new version - all the transitive dependencies will get upgraded automatically.
One of the reason that cause this is because of licensing issue.
License for such JARs prohibit public redistribution in such approach. So someone provide only the POM so that you can get the JAR yourself and install it to your local maven repo/ internal repo, together with the POM provided.

How can I get list of plugin dependencies?

It is said that:
Maven 2.0.9 introduced the ability to override a dependency used by a
plugin. This is handy when you want to use a newer checkstyle, pmd,
etc jar than is included by default in the plugin.
My question is - how can I get list of dependencies of some specific plugin just as easy as I can get list of dependencies of the project?
Executing mvn dependency:resolve-plugins will provide a list of all the plugins defined within your POM (and those inherited from any parent POMs) along with all the dependencies of each plugin.

Resources