How can I get list of plugin dependencies? - maven

It is said that:
Maven 2.0.9 introduced the ability to override a dependency used by a
plugin. This is handy when you want to use a newer checkstyle, pmd,
etc jar than is included by default in the plugin.
My question is - how can I get list of dependencies of some specific plugin just as easy as I can get list of dependencies of the project?

Executing mvn dependency:resolve-plugins will provide a list of all the plugins defined within your POM (and those inherited from any parent POMs) along with all the dependencies of each plugin.

Related

Does maven add all dependencies to modulepath by default?

I read on Java 9 Modularity book:
Dependencies are always put on the module path, even when dependency isn't modularized yet.
[...]
The most important changes made to Apache Maven for support of the Java module system are as follows:
Uses the modulepath during compilation
Supports a mix of explicit modules and automatic modules as dependencies
I'm looking at maven documentation and I cannot find this information anywhere.
Does maven by default add <dependencies> to the modulepath (only?) and if yes, after which maven version?
Also if the above is true is there a way to instruct maven to not use modulepath at all?
No, Maven puts dependencies to module path only for those Maven modules that have module descriptors (module-info.java). Non-modular Maven modules still put their dependencies to classpath.
You can run Maven with -X option to see exact command-line options that are passed to javac.

Maven submodule with pom packaging?

does it make sense to have a maven submodule (which doesn't have any submodules to itself) to have a pom packaging?
Is there any use of doing that at some instance?
If not does it mean that all my last level submodules should have a packaging which is not pom?
Typically, there is a certain lifecycle associated with the packaging, e.g. the "jar" packaging will run the maven-compiler-plugin during the "compile" phase, etc.
If you choose "pom", then there is a very limited default lifecycle - I guess only the the "install" and "deploy" plugins are bound to the respective phases. You could probably use it if you want to have more control over what happens in a build.
Typically, you only would use "pom" packaging for aggregator modules (those that have submodules).
For more details on packagings and the Maven lifecycle, you can refer to Maven: The Complete Reference - 4.2. Package-specific Lifecycles
As a real-world where I actually use "pom" packaging in a submodule:
In some projects, I have a submodule called "PROJECT-doc" which contains asciidoc documentation that I compile to HTML and PDF as part of the build. These modules have the "pom" packaging - there is no Java code to compile, no JAR to build, and no unit tests to run - just the documentation is built. I manually bind the "asciidoctor-maven-plugin" to the "generate-resources" and that's it.
I think the main question is the use of packaging pom in maven - this question was answered here: What is "pom" packaging in maven?
The short form is: yes, you shouldn't have a module without submodules that uses packaging pom.

How install Swagger without Maven

I am not MavenĀ“s user and i want configure all dependencies of Swagger in my project. I try make it unsucessful. I get thousands jars, jackson-, swagger- and nothing.
From https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X#adding-the-dependencies-to-your-application:
Projects that cannot utilize maven's dependencies would need to add
the dependencies manually. Since those may change from version to
version, the list of dependencies will not be documented here.
Instead, it is advised that you clone the swagger-core repository, go
to the directory of the relevant module (artifact) and run mvn dependency:list. That would give you a list of dependencies required
by swagger-core which you would have to include manually in your
application. Keep in mind this requires you to have maven installed
but it does not require you to use maven for your project.

Impose build order for a multi-project in Maven

I have a multi project in maven like this:
paren-project
-> plugin-project
-> testbed-project
The plugin project generates a JAR, which is manually copied to a specific subdirectory of testbed (using whatever embedded script like groovy or ant). The important point: I don't want the plugin JAR to be in the classpath of testbed.
But I cannot found the solution to force the plugin project to be build BEFORE the testbed project. If I set the plugin project as dependency of the testbed project, it is added in the classpath.
Any solution, or do I have to switch to a build system like gradle, ivy or ant ?
As it is mentioned at the http://maven.apache.org/guides/mini/guide-multiple-modules.html
Reactor Sorting
Because modules within a multi-module build can depend on each other,
it is important that The reactor sorts all the projects in a way that
guarantees any project is built before it is required.
The following relationships are honoured when sorting projects:
project dependency on another module in the build
plugin declaration where the plugin is another modules in the build
plugin dependency on another module in the build
build extension declaration on another module in the build
the order declared in the modules element (if no other rule applies)
Note that only "instantiated" references are used - dependencyManagement
and pluginManagement elements will not cause a change to the reactor sort order
Maven is a versatile system. No need to switch.
You can add the dependency like this:
<dependency>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<optional>true</optional>
</dependency>
This way, the dependency will not be included in the classpath.
Read more about Optional Dependency

How to get all Maven plugins & their versions for a specific phase?

Do you know of a way to list all Maven plugins (with their versions) that are going to be executed for a particular phase? This should include all plugins set in all parents of the current project.
One method would be to run:
mvn help:effective-pom
That will show you the projects POM after interpolation and inheritance have been applied. It should be fairly easy to look in the build configuration and determine the configured plugins for a phase from there.
http://maven.apache.org/plugins/maven-help-plugin/effective-pom-mojo.html

Resources