Maven plugins without <executions> tag - maven

I am studying Maven plugins from the official references. I read:
You can also configure a mojo using the executions tag. This is most
commonly used for mojos that are intended to participate in some
phases of the build lifecycle.
but If I do not use the <executions> tag, like this:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-myquery-plugin</artifactId>
<version>1.0</version>
<configuration>
<url>http://www.foobar.com/query</url>
<timeout>10</timeout>
<options>
<option>one</option>
<option>two</option>
<option>three</option>
</options>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
what happens?
Will we be able to run a goal from maven-myquery-plugin only in isolation giving a command like mvn myquery:myquery or does the plugin come up bundled in some phase/life cycle by default?

I also have been wondering if it's possible to skip the executions tag. As there is no direct answer on the official website I tried to make such a plugin with default phase bindings by myself and the answer is: no goals will be executed if they weren't specified in the executions tag. Such a plugin (goal) could be executed only by direct command: <plugin>:<goal>

Related

running secbugs maven plugin from command line/ maven plugin configuration parameters in command line

maybe this is a generic question with regards to how to transfer maven plugin paramters from the pom.xml to the commandline, but I have usually done this without problems using the method below. For the find-security-bugs plugin, however, it is not working.
The find-security-bugs plugin docu says that you can configure the plugin in your pom.xml as follows:
<plugins>
[...]
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.2.1</version>
<configuration>
<includeFilterFile>spotbugs-security-include.xml</includeFilterFile>
<plugins>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>1.12.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
I would like to do the same, but cannot do any changes to the pom.xml I'm testing, so would have to specify everything in the command line.
I'm running (from powershell, therefore the quotation marks):
mvn com.github.spotbugs:spotbugs-maven-plugin:4.7.2.1:check -"Dplugins.plugin.groupId=com.h3xstream.findsecbugs" -"Dplugins.plugin.artifactId=findsecbugs-plugin" -"Dplugins.plugin.version=1.12.0" -"DincludeFilterFile=secbugsfilter.xml"
but the parameters are not used. Is there any way to run a plugin with a configuration like this from the command line without specifying anything in the pom?

Should pluginManagement be used in submodules?

I am reading sonatype's tutorial on multimodule projects and I see that in submodule they use the <pluginManagement> configuration like this:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This confuses me as I thought that <pluginManagement> is to be used in parent POM to provide common plugin configuration for submodules. What are the reasons for using plugin managment in children poms ?
Most of the time <pluginManagement> is used in parent pom files.
It configures plugins. But makes them not active part of the build. Therefor you need to add them to the <plugins> part of the Maven pom file. Most not done in parent pom files, but done in the (sub) modules, using / refering to that (parent) pom.
I think this is special to the use of the surefire plugin.
Since you execute the plugin with mvn test the surefire plugin will be executed with the configuration specified in the pluginManagement block. Other plugins are not executed directly but by binding them to another lifecycle phase and thus must be specified in the plugin block.
See the usage page of the surefire plugin.

configuring maven plugin with a custom packaging

I have written a custom maven plugin which works in package phase of maven's default life cycle. In addition I have added a custom packaging type to it. In order to support the custom packaging type I have introduced components.xml so it will override the default maven life cycle. In the component/configuration/lifecycles/lifecycle/phases/package section of component.xml I have added my plugin to execute in package phase.
When I use my plugin I pass the configuration to the plugin through the pom.xml as follows;
<build>
...
<plugins>
<plugin>
<groupId>sample</groupId>
<artifactId>sampleArtifact</artifactId>
<extensions>true</extensions>
...
<executions>
<executions>
<phase>package</phase>
<goal>generate</generate>
<configuration>
//Configuration goes here.
</configuration>
</executions>
</executions>
...
</plugin>
</plugins>
...
</build>
Problem:
the configuration I passed into mojo as above is not getting set in the mojo. However, if I set the plugin configuration in one level below the tag(where the executions tag present), then it works. Since this plugin works in package phase I need the plugin configuration passed in through as above. Without custom packaging, the above configuration works well. Any thoughts on what I miss here?

How to configure FindBugs to run only on one project in a multi-module maven project

I use the findbugs-maven-plugin to check for bugs with maven. My maven project is a multi-module project that roughly looks as follows:
java-module
pom.xml
src/ ...
pom.xml
scala-module
pom.xml
src/ ...
I use Jenkins to build and test the project, and Jenkins runs goal findbugs:findbugs in the top-most directory. Since FindBugs reports many spurious warnings for code that is generated by the Scala compiler, I would like to tell FindBugs not to analyze the code in scala-module. However, when I run findbugs:findbugs in the top-most directory, it always analyzes all classes in java-module and scala-module. How can I tell maven to ignore scala-module as a whole? I know about FindBugs exclude filters but I would to have a configuration option for FindBugs that tells it to simply not analyze the code in a certain submodule.
FindBugs is configured in pom.xml in subdirectory java-module as follows:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${version.plugin.codehaus.findbugs}</version>
<configuration>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
</plugins>
</reporting>
Despite the configuration being done only for the java-module, FindBugs will always also analyze scala-module.
Add a configuration the scala-module pom.xml that explicitly instructs findbugs to skip the module, i.e.
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</reporting>
Note that Maven often requires you to repeat boilerplate XML for cases like this.
Noahlz's answer did not work for me, but adding the following snippet to the sub-module's POM.xml did the trick.
<properties>
<findbugs.skip>true</findbugs.skip>
</properties>

How to create jar archive of projects sources with maven

I include the following snippet in a projects object model
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
</plugin>
according to maven.apache.org the plugin attaches the jar goal to the package phase.
However doing "mvn clean ; mvn package" does not generate a project-sources.jar in the target directory.
EDIT: Propably i do not understand the comment from the website, which i quoted: "[The source:jar goal] Binds by default to the lifecycle phase: package." I expected that, when i include the plugin section as shown above maven already binds the source:jar goal to the package phase. Am i mistaking here? What does the comment mean?
matthias.
The documentation is a little misleading. The plugin has a default execution phase of package but there is no default goal. I believe that you have specify a goal in order for the plugin to work.
You need to bind the plugin to a maven life-cycle goal for it to generate the source jar. Otherwise, you need to invoke it explicitly mvn source:jar.
As documented here, you can bind it to the jar goal.
Try this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
It uses then the default binding of jar-no-fork goal to package phase of the lifecycle and that's probably what you need here.

Resources