Is there a performance impact with having circular dependencies? With Gradle?
Dependencies in gradle are discouraged to avoid confusion. When it comes to circular dependencies, you should keep the following in mind:
Gradle does not support circular dependencies within individual configurations
Gradle can support two or more configurations depending on each other, unless
There is a compile or implementation circular dependency
In general, these restrictions limit any use case of circular dependencies, and it's highly recommended to refactor them out of your project instead.
Related
I'm trying to refactor a big project, and there is also a big pom. I want to refactor it and remove unused dependencies. I used
mvn dependency:analyze
to look at some unused dependencies. The fact is that some libraries used at runtime are considered unused, like this answer said: https://stackoverflow.com/a/42967645/18089908.
In addition, in my pom all the dependencies are missing the scope tag.
Is there a way to see which dependencies are required at runtime?
There is no general way to do this.
Read the docs and run your integration tests.
Maven includes transitive dependencies in a project class path to eliminate the need to redefine these dependencies over and over again each time a module depends on a third party module.
The version of transitive dependencies used can be controlled from a dependency management section in the root pom. So it is controllable.
So why using transitive dependencies in a project without explicitly declaring it in its pom file is considered a bad practice ?
Usually, you update your dependencies after some time.
The update can lead to lost transitive dependencies which will then directly affect your program.
If, on the other hand, you write down all dependencies you use explicitly, it is much easier to make updates and see what you really use.
In maven, dependencyManagement can be used to resolve dependency conflict problems.
Now I'm developping a common lib project which will be used by many other projects. I want to use dependencyManagement to resolve all dependency conflicts so that other projects don't need to handle it.
However, when I add the common lib as dependency of other projects, I find that the dependencyManagement not works. In other words, I meet the same dependency conflict problems which already been resolved in dependencyManagement of the common lib.
I know copy-paste of dependencyManagement to everywhere is a way to make it, but it's very ugly and hard to maintain.
Is there any other way to achieve the goal?
Thanks.
Yes, your "common lib" can declare the desired versions as <dependency> (not just in dependencyManagement) and can also use exclusions to exclude the undesired ones. This works also transitively.
It would be great to have transitivity also for dependencyManagement, but it might make the very complex dependency resolution process of Maven even more complex.
I am using Maven to build my project. There are lot of dependencies which are in provided and runtime scope. The build size is large and I want to remove the unwanted dependencies. So is there any way in which I can check which dependencies are unwanted.
The best way to minimize dependencies to the ones you really need is to not embed that dependencies. If you simply use the maven-bundle-plugin on your code it will create Import-Package statements for the code you really need. This might even give you a good hint on what dependencies you might be able to exclude for embedding.
In general in OSGi the goal should be to not have that many dependencies in the first place. If you use libraries with extensive dependencies then your should question the quality of these.
I have to add a new dependency to a maven project. This dependency has four transitive dependencies(according to http://mvnrepository.com/) and between them, there is spring-data-jpa jar.
The maven project I am working in has many dependencies configured in the pom so I understand there could be a big possibility that there is already a spring-data-jpa dependency in the project(transitive or not).
When you work in a large project with many dependencies and you have to add a new one, how to check if there is already the same transitive dependency of a different version? I have to check manually the transitive dependencies for each direct dependency configured? Has maven a warning for this situation?
How maven works in this situation? I mean, there could be two spring-data-jpa jars of different versions(this would be a problem) or maven resolves this in another way?
The simple answer is that the dependency plugin can tell you. The longer answer is that there are a number of different situations to consider about transitive dependency management, and how the plugin helps and what to do about it differs for each one.
Maven automatically chooses which dependency to include if two dependencies have the same coordinates (groupId, artifactId) with different versions. Broadly speaking, it picks the version that's highest in the tree - effectively overriding dependencies defined in downstream transitive dependency poms. So, if you have two different versions of exactly the same dependency then you will still only find one version of the dependency on the relevant classpath.
The dependency plugin can help you identify this situation by highlighting points where its made a decision, but you probably want to use the dependencyManagement section of your top-level pom to ensure that the dependencies which you bring in are the ones you expect.
Separate difficulties can arise when a dependency changes its groupId or artifactId. Then you can get two dependencies on the classpath - one with an old version on the old coordinates and one with the new version on the new coordinates. As examples, Spring, Hibernate and Apache commons have all found themselves doing this at some point or another. In this case all you can do is use to the dependency plugin to identify duplicated dependencies and then use exclusions tags to explicitly exclude them as transitive dependencies from the dependencies which are pull them in.
It's important to note that all of this dependency management can cause unintended breakage. If the thing that your application depends on really does depend on some specific version of a package as a transitive dependency then you can break it by overriding that version. So testing the features that you use is essential.
Have you tried the Maven Dependency Plugin? There's some useful goals you can run, such as mvn dependency:tree etc.