Reputation: 11
Is there any way I can copy one pom.xml dependencies into other pom.xml
Update: Well, I have project A and Project B.
Project B is using some dependencies ( like Junit.jar, commons-httpclient, commons-collections, struts)
In the Project A : I would like to copy all project B dependencies in some out folder
This I can specify manually all dependencies jars of Project B in Project A but I would like to do automatically some script in Project A pom.xml.
Note: I don't want to build the project B in Project A pom.xml , I am building Project B separately
Does this make any sense?
Upvotes: 1
Views: 2442
Reputation: 298838
I think the maven invoker plugin does pretty much exactly what you need:
http://maven.apache.org/plugins/maven-invoker-plugin/install-mojo.html
Or create a java class using the maven API, programmatically build a maven project and export the dependencies
start here: http://maven.apache.org/ref/2.2.1/maven-project/apidocs
read a model: http://maven.apache.org/ref/2.0.11/maven-model/apidocs/org/apache/maven/model/io/xpp3/MavenXpp3Reader.html
construct a MavenProject object using the model: http://maven.apache.org/ref/2.2.1/maven-project/apidocs/org/apache/maven/project/MavenProject.html#MavenProject(org.apache.maven.model.Model%29
resolve and export the dependencies
Sean
Upvotes: 1
Reputation: 570315
While I understand the spirit of the question (and only the spirit), the relation between project A and project B is still unclear so I'm not sure of the best way to implement this. Here are the options.
First solution: leverage transitive dependencies. There are some rules about them, but basically, if you declare a dependency on Project B in Project A, you'll get some of its dependencies transitively.
Second solution: use inheritance.
Third option: use another project of type pom
to group the dependencies and declare a dependency on this pom.
Upvotes: 1
Reputation: 343
If I understand well what you mean, keep only the dependencies in project B pom.xml. If you need something else in this pom, create another directory level B1, and push every other elements in it. Then makes B pom.xml a pom packaging with one module:B1.
Then you can make project B pom.xml the parent of project A pom.xml. A will inherit dependencies from B.
Upvotes: 1