I'd like to mvn install:install-file artifact A excluding artifact X.
A does not depend directly on X, yet down the dependency tree there are several dependencies for X.
What would be the command to perform this?
If you just run install:install-file on a jar file without -DpomFile=something, it will create a pom with no dependencies, so there's nothing to exclude. The 'X' dependency won't be represented at all.
If you pass in a pom file via -DpomFile=POMFILE, then you have the dependency structure in there, and it can include whatever exclusions you need. If you put in a dependency on X, and it in turn depends on Y, you can add an exclusion to the X dependency.
A comment from the OP suggests that this has nothing to do with install:install-file.
There is some artifact 'A' with a rich and complex dependency tree, which transitively reaches some artifact 'B' at many points. How do cope with B not being available if, in fact, it's not actually needed in the classpath?
The only solution here is to add exclusions to the POMs that reference A. Instead of trying to change the pom of A to exclude B, you have to add the exclusion of B in your own poms as part of the dependency on A. There's no other way.
Related
I have a maven multi-module project . In the parent module there is a certain dependency which is mentioned in dependencyManagement-> dependencies section say x.
Now in one of the child modules , few classes belonging to artifact x are being used.
So, ideally mvn clean install should not pass as we also need to mention the same dependency in the pom of child module.
But surprisingly mvn clean install passes from the command line but Intellij Idea asks to add dependency to the child pom. What might be the reason behind this behaviour
Impact of exclusion in the context of jar packaging(simple/fat jar using shade plugin). What i mean here, how can it be verified by extracting the jar.
When a dependency is excluded, it is removed from the dependency tree at that point. You can check this with mvn dependency:tree. It might still come in through other ways (e.g. as transitive dependency of some other dependency). You can check that with mvn dependency:list.
I have a situation where in my EAR file I have 'N' number of JAR files[modules] present. In these JAR files, there are certain artifacts which are duplicate. By duplicate, I mean the artifact name is same but with different versions.
Ex:
adapter-base-59.0-20141219-311675-3.jar
adapter-base-60.0-20141223-678915-68.jar
I would like to get help on how to find the source pom file location for these JAR files.
Any help on this is highly appreciated.
Regards,
Deepan
that might be a bit painful but the dependency can be in a parent pom.xml, a transitive dependency or a profile. Profiles can be in a settings.xml as well.
What I would do is execute mvn dependency:tree on the pom.xml where the dependencies are copied and then search where it comes from. Then follow that path.
It is a little weird you have the same jar twice with a different version. Usually maven takes the first one (or closest one) it find. So adding the correct version to your pom.xml has a distance of 1, that would always win - any transitive dependency will have a greater distance.
It might be the dependency uses a different groupId and maven cannot detect its the same artifact.
You could also try to open the jar files - maven usually adds some information into the META-INF directory (if you're lucky and the jar was release with the maven-release-plugin).
Apache Velocity needs commons-collections-3.2.1.
In my pom file I have added a velocity dependency. Everything works, but when I look in the overall pom file:
$ mvn help:effective-pom
I do not see an commons-collections entry.
I had expected it should be there. Or not?
No, not if you don't specify it directly. effective-pom shows the pomfile factored in with the eventually inherited definitions from the parent pom (ie. dependencyManagement, pluginManagement, properties and so on) and the profile.
To see the full list of dependencies, including transitive dependencies, you need maven-dependency-plugin, and
mvn dependency:tree
The effective-pom does not show you all the transitive dependencies, only the POM as it will be, given whatever parents, profiles etc. you have.
You may want to try mvn dependency:tree, which will show you the projects' direct and transitive dependencies as a tree, and notice that commons-collections will be somewhere under Velocity.
Cheers,
I've got a project with Maven in which one subproject (A) wants to depend on another subproject (B) which uses "pom" packaging.
If I do this the straightforward way, where A specifies a dependency on B with <type>pom</type>, things work perfectly if I do "mvn install", but if I run any phase earlier than install, such as mvn compile or mvn package, then it fails while trying to build A: it goes looking for B's pom in the repository, and doesn't find it.
I don't really want this pom in the repository, because it's part of our active source code and changes frequently.
For all the jar-packaged projects we build, it seems to work fine to keep them out of the repository, build with mvn package, and Maven knows how to find all the dependencies in the source and build trees it manages without resorting to the repository; however for the pom-packaged project it always wants to go to the repository.
A couple things I learned while trying to understand this:
Maven best practices encourage you to use pom-packaged projects to group dependencies, but with the added step of "mvn install" on the POM project
Maven lifecycle documentation says "a project that is purely metadata (packaging value is pom) only binds goals to the install and deploy phases"; maybe this is why the POM project is invisible as a dependency target unless I invoke the install phase? I tried binding the compiler plugin to the compile phase and this didn't seem to help.
Is there a way that I can specify the POM subproject as a dependency of another subproject in the same parent project, without installing the POM project to the repository?
It isn't purely a question of which goals are bound to which lifecycle phases for POM projects. If it were, then binding the "package" goal would solve the problem.
When building a multi-module project, Maven reads the POMs of all modules to determine dependencies between modules, so that it can build the depended-upon modules before the depending modules. It's able to achieve this even when running the "package" goal (such that the depended-upon modules are not yet in the local repository).
Therefore, the code that constructs the classpath for builds must be managing several cases, notably:
extra-project jar dependency, where it looks for the POM in the local repository, handles its dependencies, and adds the POM's jar to the classpath
extra-project pom dependency, where it looks for the POM in the local repository and handles its dependencies
intra-project jar dependency, where it looks for the POM within the project tree, handles its dependencies, and adds that module's target/classes folder to the classpath
intra-project pom dependency, where for some reason it doesn't look for the POM within the project tree, and therefore doesn't handle it's dependencies.
Notice the asymmetry in the last two cases, as compared to the first two.
I can see two solutions to your problem. One is to file a bug report, or rather a request to change the behaviour (since it's obviously intentional), perhaps only for the case of intra-project dependencies on multi-module projects. Or indeed propose a patch. But since the behaviour is intentional, you might meet a refusal. In the best of cases, you're in for a long wait. (I'd vote for your bug report though - I've been stung by that same behaviour, in a different context.)
The other solution is simply to run an install on your project. I don't really understand why you don't want the POM project in your repository: if needs be, you can use a snapshot repository, where it doesn't matter if things change frequently, to avoid polluting your main repository.
Configuring maven-install-plugin to run during the compile phase, and copy the relevant pom.xml to the repository, seems to accomplish what I wanted as far as Maven itself is concerned, though m2eclipse still is not happy (it throws "failed to read artifact descriptor" errors with no additional description for the pom.xml that has a dependency on the other POM project).