How to find the version of a Maven plugin in the project? - maven

I'm trying to find the version of maven-wagon plugin that's being used in my project. Is there a way to find the version of a used plugin via command line?

There are several ways to do this:
1) Check the dependency tree:
To find out the libraries and versions you are using you can use the Maven dependency tree, just execute this where you have your project (pom.xml):
mvn dependency:tree -Dverbose
This is useful detect which version of an specific library your project is using, but I think it doesn't include plugins.
2) Describe the specific plugin:
If you want to know what version of an specific plugin you have installed you can do this:
mvn -Dplugin=: help:describe
mvn -Dplugin=org.codehaus.mojo:wagon-maven-plugin help:describe
This shows you something like this:
Name: Maven Wagon plugin
Description: Maven plugin that can be used to access various operations on a
given URL using a supported maven wagon. Supports recursive upload, download,
and list directory content functionality.
Group Id: org.codehaus.mojo
Artifact Id: wagon-maven-plugin
Version: 1.0
Goal Prefix: wagon
This plugin has 11 goals:
...
...
3) Check the effective pom:
Execute this:
mvn help:effective-pom
and go through the pom looking for the plugin you need to clarify, there you will find something like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
</plugin>

Related

How to replace a property in a POM in a Maven/Jenkins job?

I have a project with client and server components. Both have their own Maven multi-module build projects.
The correct server version must be referenced in various frontend modules. To accomplish this I set a property in my client parent POM like this:
<properties>
<server.version>1.2.3</server.version>
</properties>
Now I'd like to update the version number in the POM (i.e. not just injecting a different version from the command line with -D...) during/after a Jenkins build job. Is there a way to do this?
I found the com.google.code.maven-replacer-plugin:replacer Maven plugin which works perfectly for my case. It accepts an xpath and a regex to define what to replace in an XML file.
Example plugin configuration:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<configuration>
<file>${project.basedir}/pom.xml</file>
<xpath>/project/properties/server.version/text()</xpath>
<token>^.*$</token>
<value>${newServerVersion}</value>
</configuration>
</plugin>
And the plugin can be run for each affected maven module:
mvn --non-recursive replacer:replace -DnewServerVersion=xxxx
At itembase we use Jenkins Pipeline Plugin. It comes with some useful built in functions like for example readMavenPom and writeMavenPom. So in your build pipeline you could do something like:
def pom = readMavenPom file: 'pom.xml'
//Do some manipulation
writeMavenPom model: pom
Did you check maven versions plugin?
(Tbe website is shutdown but the plugin page is still avaiable in google cache)
mvn -DnewVersion=<version> versions:set

How does Maven resolve plugin versions?

I'm reading the docs and still confused as to how Maven is deciding which versions of plugins to download.
For example, consider this simple scenario:
an empty local repository
a default settings.xml
run a simple maven command. for example, mvn archetype:generate for the maven-archetype-quickstart as described in the Maven in 5 Minutes doc.
After running the command, the first thing Maven does is download a bunch of plugins.
Some of the plugins Maven is downloading include:
maven-clean-plugin-2.4.1
maven-install-plugin-2.3.1
maven-deploy-plugin-2.5
Why those versions?
The most recent version of these plugins are:
maven-clean-plugin-2.5
maven-install-plugin-2.5.1
maven-deploy-plugin-2.8.1
I looked at the LATEST version metadata for maven-clean-plugin and it's 2.5
It's not that I necessarily want to force Maven to use different versions of these plugins, I just want to understand WHY it's resolving to those versions.
I'm using Apache Maven 3.0.3
Maven defines 3 lifecycles in META-INF/plexus/components.xml:
1. Default Lifecycle
Default lifecycle are defined without any associated plugin. Plugin bindings for these lifecycles are defined separately for every packaging in META-INF/plexus/default-bindings.xml
e.g. Plugin bindings for jar packaging
<phases>
<process-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:resources
</process-resources>
<compile>
org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile
</compile>
<process-test-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
</process-test-resources>
<test-compile>
org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testCompile
</test-compile>
<test>
org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:2.4:jar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
</deploy>
</phases>
2. Clean Lifecycle
clean lifecycle is defined directly with its plugin bindings.
<phases>
<phase>pre-clean</phase>
<phase>clean</phase>
<phase>post-clean</phase>
</phases>
<default-phases>
<clean>
org.apache.maven.plugins:maven-clean-plugin:2.5:clean
</clean>
</default-phases>
3. Site Lifecycle
Site lifecycle is defined directly with its plugin bindings.
<phases>
<phase>pre-site</phase>
<phase>site</phase>
<phase>post-site</phase>
<phase>site-deploy</phase>
</phases>
<default-phases>
<site>
org.apache.maven.plugins:maven-site-plugin:3.3:site
</site>
<site-deploy>
org.apache.maven.plugins:maven-site-plugin:3.3:deploy
</site-deploy>
</default-phases>
If you want to override these default plugin version you can do it from command prompt as follows
mvn org.apache.maven.plugins:maven-clean-plugin:2.0:clean
instead of
mvn clean:clean
Every version of Maven binaries has certain versions of plugin versions hardcoded. That's to make a somewhat reproducible build in the cases when user doesn't provide his own version information. Which you are encouraged to do and once you populate <pluginManagement> section with the plugin versions of your choice, the build will start using it.
It becomes quite clear if you use -X option when building your projects. Please, check my answer in another thread:
https://stackoverflow.com/a/48874533/4470135

Wro4j maven plugin - required class is missing

I'm trying to run wro4j maven plugin according to the documentation
I add the plugin to my pom.xml:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
and run the goal:
mvn wro4j:run -Dminimize=true -DtargetGroups=all
However the build fails with error:
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the pl
ugin manager executing goal 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run': Unable
to load the mojo 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run' in the plugin 'ro
.isdc.wro4j:wro4j-maven-plugin'. A required class is missing: org/codehaus/plexu
s/util/Scanner
Do you know how to avoid this error?
Since wro4j-1.5.0, the maven 3.0 is required to run the plugin. The reason is a feature called incremental build support which depends on a library which is not available on older version of maven by default.
The issue is on your local environment.
Go to this folder on my windows machine:${user.home}/.m2/repository, then delete everything in this folder. (Well you can keep a copy.)
After deleting, run the Maven command:mvn clean install -U.
See: https://groups.google.com/forum/#!topic/wro4j/ZPSFBQ_5lI8

How to distribute a binary dependency in maven?

I'm trying to convert a project from ant to maven.
The unit tests depend on a third party binary jar, which is not available in any public maven repositories.
How do I make maven handle this situation? I have found two solutions, neither of which are acceptable. First is to use a system dependency; this doesn't work because a) the dependency should only be for the tests, and b) the dependency is not found by eclipse after generating an eclipse project.
Second is to manually install the dependency in a local repository. This seems to be the recommended way. I don't want to do this because I want users to be able to build and test with a simple 'mvn test'. If users have to read a document and copy/paste some shell commands to be able to build and test, then something's wrong.
I suppose it would be OK if maven itself installed the dependency in the local repository as part of the build - is this possible, and if so, how?
Aled.
You may want to look at install:install-file. You can make it execute in the early phase of your project (validate or initialize) via standard means.
On the second thought, if it fails because of missing dependency in the same project, there are couple more options. One is to call ant script via antrun plugin to install artifact.
Or create additional module not dependent on your artifact to be executed prior to main module and have that module install artifact as described earlier.
First of all my way would be using a repository manager such as nexus and installing this dependency to there.
However there is another solution. You can include this 3rd party jar to your project and with test plugin you can configure to include it in classpath such this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>path/to/additional/resources</additionalClasspathElement>
<additionalClasspathElement>path/to/additional/jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
By the way, I hope that you are aware of that maven is executing surefire plugin in order to run tests by default lifecycle.

How to build plugins having different versions from a single parent pom.xml?

I am trying to build several Eclipse plug-ins with Maven Tycho. All the plug-ins does not have the same version number.
Let's say the following pom architecture:
plugin1 (version 1.0.6.qualifier) / pom.xml
plugin2 (version 1.4.0.qualifier) / pom.xml
pom.xml (parent pom version 1.0.0.SNAPSHOT)
Maven's build fails with the following error:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.12.0:validate-version (default-validate-version) on project plugin1: Unqualified OSGi version 1.0.6.qualifier must match unqualified Maven version 1.0.0-SNAPSHOT for SNAPSHOT builds
How to configure the parent pom to be able to build those plug-ins with different version numbers?
Should I use a different pom architecture to solve this issue?
Note that I don't want to modify plug-in's versions.
maven POM version and MANIFEST version must match (with suffix ".qualifer" in MANIFEST replaced by "-SNAPSHOT" in pom.xml).
See http://wiki.eclipse.org/Tycho/Packaging_Types#eclipse-plugin
You can configure tycho plugin like that in order to only Warn versions problems : http://www.eclipse.org/tycho/sitedocs/tycho-packaging-plugin/validate-version-mojo.html
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<configuration>
<strictVersions>false</strictVersions>
</configuration>
</plugin>
</plugins>
Result :
[INFO] --- tycho-packaging-plugin:0.16.0:validate-version (default-validate-version) # org.apache.commons.io ---
[WARNING] Unqualified OSGi version 5.1.0.qualifier must match unqualified Maven version 2.1.0-SNAPSHOT for SNAPSHOT builds
I found a solution. I added a version tag corresponding to the Eclipse plug-in version in each modules' pom.xml.
Is it possible to use maven pom.xml files without any version tag and let tycho using version specified in MANIFEST.MF files?
Even i have faced the same problem and found the solution for the same.
Actually the problem is Manifest.MF file version and pom.xml parent version should be same otherwise we will get this error.
Manifest.MF
Bundle-Version: 2.5.0.qualifier
pom.xml
<parent>
<groupId>com.example.pma</groupId>
<artifactId>com.example.pma.product.parent</artifactId>
<version>2.5.0-SNAPSHOT</version>
<relativePath>../com.example.pma.product.parent</relativePath>
</parent>

Resources