I am writing a plugin where I need to get all the dependency artifacts of a project including test scope and all of the transitive dependencies as well. project.artifacts seems to get me all the dependencies if I run the plugin in the install phase (I cannot run it before that), except it does not get me test scope dependencies and any transitive dependencies of these test scope dependencies. How do I get the transitive dependencies of everything?
I have also tried project.dependencyArtifacts which doesn't seem to help. It gets the test scope direct dependency but not the transitive ones.
Working with maven 2.0.9
Posting for reference:
I had to set #requiresDependencyResolution test which then included all the transitive dependencies. It was initially set to runtime. This fixed my issue.
Related
We have splunk-library-javalogging as compile-dependency and added com.squareup.okhttp3/okhttp as a test-dependency. okhttp is also a compile-dependency of the splunk-appender.
Using spring-boot-maven-plugin we realized the okhttp-Dependency is no longer included, when added as a test-dependency. Removing it, it is included again.
So it seems scoping okhttp as test overrides the transitive compile-dependency (excluding it from the jar) - and this doesn't feel correct!?
This does not feel correct, but it is unfortunately the case.
Maven determines the scopes first, then creates the classpaths. And direct dependencies override transitive ones.
It would be smarter to create the compile classpath by just ignoring test scoped dependency entries, but this is not how Maven does it.
Quintessence: Only add a test dependency if the dependency is not already in mvn dependency:list.
I am using gradle for dependency resolution but we rely on a library with cannot be resolved from a repo. As a workaround they asked us to use a workaround like :
implementation (files($network-file-path/lib.jar))
but this in turn is bringing a lot of transitive dependencies and causing a lot of trouble. I am very new to gradle and could not find a fix.
Is there a way through I can omit all the transitive dependencies of this specific jar ?
We are using gradle version 7.3.3
Known: npm
I am used to npm and JavaScript and whenever the dependency tree changes, there is a changed package-lock.json generated. This file includes all dependencies and their transitive dependencies with resolved/fixed versions.
Unknown: mvn
Now i have to use Maven and Java.
The question is: What's the maven-equivalent of npms package-lock.json?
I would need this information as to efficiently track which exact versions of (transitive) dependencies are contained in my project/bundle.
In Maven you usually do not use version ranges - so you'll always have a defined version for a dependency. If you want to change the version of a transitive dependency you can do this using the dependencyManagement block (which is similar to the new npm overrides).
If you want a report of the exact dependencies used check out the Maven Dependency Plugin. You can run a mvn dependency:tree to see all dependencies (with relations) including versions.
For more information about Maven dependency mechanism see Introduction to the Dependency Mechanism
I'm trying to build a Java project with Maven. My pom.xml includes mainly dependencies, some of which have their own transitive depedencies.
When I run 'mvn compile' most dependencies are loaded fine, but some of the transitive ones are not found, giving the warning "[WARNING] The POM for artifact_name is missing, no dependency information available". This leads to the Maven compile to fail.
The logs show, that the dependencies have been searched from Maven and Jboss public repositories.
What can I do in this situation, when a transitive dependency is not found?
How can I determine what dependency requires this transitive dependency? Command 'mvn dependency:tree' does not work, as it ends in build failure
Thanks in advance!
EDIT: I decided to delete all changes made to the pom.xml and downloaded the original one. After that the warnings with the transitive dependencies went away. So it seems that the issue was possibly with the syntax or some other change in the pom.xml.
I decided to delete all changes made to the pom.xml and downloaded the original one from our repository. After that the warnings with the transitive dependencies went away. So it seems that the issue was probably with the syntax or some other change in the pom.xml
I have Maven dependencies with scope test.
I add flag Dmaven.test.skip=true but Maven still brings test dependencies.
Is there a way not to bring test dependencies if I want to build only the production part?
This is how maven works - it First tries to check that ako dependencies are available, no matter their scope. Only then it continues to test phase to find out that tests should not be executed.
A possible workaround is to define your test dependencies in a separate test maven profile, which is not applied when you do not want to run tests. Profiles are resolved before any dependence are downloaded, therefore if test dependencies are not added by the profile to the effective pom, they are not downloaded at all.
the flag -Dmaven.test.skip will only skip compilation and execution of your tests within the project you run.
Its often better to use -DskipTests as this will compile the test classes but not run them. See surefire documentation.
This has nothing to do with dependencies. Those are loaded into the classpath depending on their scope and what plugins require. The surefire plugin requires resolution of scope test as it runs the unit tests.
If there are dependencies of scope test which you do not want to use you need to remove them or exclude them if they come in via transitive dependencies (dependencies of dependencies). You can execute a mvn dependency:tree to figure out why jar are in the project.
If you add some dependencies for test scope, maven will first check if the dependency is available or not then it checks the scope.
You can create a maven profile, add test dependencies under the profile and trigger the profile when -Dmaven.test.skip or -Dmaven.test.skip=true option is not present. In this way you can keep your build command unchanged.
You can check this simple project manage-test-dependencies-in-maven-the-proper-way to understand it better.