Listing maven dependencies in a directory - maven

I want to get all the maven dependencies list for a directory containing multiple projects. I can go inside each project and use command mvn dependency:tree and consolidate all of them manually.
Is there anyway (script or command) i can get consolidate list for all the project dependencies within parent directory.
Thanks for help.

You can define a dummy project, add all your projects as dependencies and then call dependency:list on this dummy project.

Related

How to configure maven based project?

I have a Spring Boot 2 project, the pom of this project contains some dependencies and two of those dependiencies are my another projects (libs). Lets call it LP1 and LP2.
To make SpringBoot run possible, I always need to run "mvn clean install" in the folder of LP1 than run it again in LP2 and now finaly run it again on SpringBoot2 project. Otherwise I got an error cause maven cant find LP1 or LP2 or both.
It is possible to configure my projects another way so I can run "mvn clean install" just once? My Folder Structre looks like this
Root
-SpringBootProjectFolder
-LP1
-LP2
Create a parent Pom for your project and add LP1 and LP2 as dependent modules. This way triggering the build for parent project will first build sub modules. For more details refer this How to make maven build of child module with parent module?

How to copy all the dependencies in Maven project modules to a directory?

I have a big local maven project that contains multiple modules which are inturn maven projects and are dependent on one another.
Ex.
parent pom.xml
<pom>
<module1> #jar
<module2> #dependent_on_module1.jar
<module3> #
</pom>
I have mentioned the sequence to build those modules in the parent pom.xml .
I also mentioned where to place the artifacts when they're built in groudId and artifactId.
But in the dependencies for all those modules, I have mentioned a common local system path for all those modules.
Is there any way to copy all the artifacts which are being created for modules when maven build is performed on the parent pom to a specific directory that can be dynamically mentioned when the maven command is run.
I have searched for maven copy command. But looks like it's not going to do what I want.
Any suggestions?

How to get all the specified jars mentioned in the pom.xml and transitively dependent jars?

I have only the POM file using which I need to write a script to automatically download all the dependency files and output to custom mentioned path.
I just want to achieve the above using mvn command in command line.
It sounds like you're looking for mvn dependency:copy-dependencies:
dependency:copy-dependencies takes the list of project direct dependencies and optionally transitive dependencies and copies them to a specified location, stripping the version if desired. This goal can also be run from the command line.
From the project root, invoking on the command line
mvn dependency:copy-dependencies -DoutputDirectory=...
will copy all your project direct and transitive dependencies to the specified output directory. If those dependencies are not already in your local Maven repository, they will be downloaded from Maven Central (or from a custom repository).

Maven: Get artifact list of sub modules

I have a root parent maven module which has lot of sub-modules that build jar files as artifacts.
I cannot change all sub-module pom.xml files.
From the root parent pom.xml is there a way I can get a list of all jars (artifacts) built by sub-modules?
Preferably after the package phase is complete?
PS: As a part of root module build I want to generate a report using a tool which requires this list of jar files.
There's a target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst in a Maven project.
You can use the GMavenPlus Plugin and Walking the File Tree to gather these files and put their content where you want.
Another option is to develop an own Maven plugin that does the same.

Can I make a Maven plugin that generates a project and then builds that project?

Is it possible to combine the capabilities of an archetype and a normal Maven plugin into a single plugin?
I have a custom language which I can compile into Java source code. I've written a Maven plugin which does this in the generate-sources phase, adds the Java source to the project, and builds the project. It works as I'd expect.
However, to use it, I need to first write out a pom.xml file referencing my plugin and describing where the input files live. I'd like to be able to go straight from raw input files to compiled code in a single maven command.
For example, suppose I have this directory structure:
my-project/
some-input-file.dsl
I want to run
bash$ mvn com.waisbrot.plugin:generate -DgroupID=com.waisbrot package
and after Maven's done running have:
my-project/
some-input-file.dsl
pom.xml
target/
generated-sources/
plugin/
SomeInputFile.java
classes/
com/
waisbrot/
SomeInputFile.class
some-input-file-1.0.jar
Actually, the integration testing of the archetype allows you to declare the parameter and goals. So do this:
Pick the template project you want to create
mvn archetype:create-from-project. It will create a new archetype
Review src/test/resources/projects, especially goal.txt and archetype.properties (source: http://maven.apache.org/archetype/maven-archetype-plugin/integration-test-mojo.html). Tweak so install will be implicity
mvn verify will be able to build the archetype, run the it, and get it installed
Hope it helps

Resources