Maven(pom.xml) do not run a plugin during deploy/install phase - maven-3

If I have a pom.xml with the following code:
<build>
<plugins>
<plugin>
<groupId>something</groupId>
<artifactId>XXX</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugins>
</build>
When I run mvn clean package, I want to run that plugin(which actually runs).
but
If I run mvn clean deploy, given phase package is previous to phase deploy is gonna run either(which I don't want to).
Is there any way to not run this plugin during deploy?
By the way: I cannot modify the mvn command executed, I need to do this inside the pom.xml file

The only way that I know to selectively enable a plugin is through Maven profile:
<project ...>
...
<build>
...
</build>
<profiles>
<profile>
<id>someprofile</id>
<build>
<plugins>
<plugin>
<groupId>something</groupId>
<artifactId>XXX</artifactId>
...
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
You would then run mvn package -Psomeprofile to run the plugin, or mvn deploy to not run it.
There are additional ways to automatically activate a profile. You will have to read the docs to see if any of those apply to you.

Related

mvn serenity:aggregate runs 0 tests and index.html has 0 results however mvn clean verify works and gets results

We have Serenity Cucumber integrated with Maven for REST API automation project running with Junit. Whenever trying to execute the command mvn serenity:aggregate results on console shows "Build success' but with 0 requirements loaded and index.html has 0 results and generated under target/site/serenity. Whereas if run with the command mvn clean verify getting results under the same folder.
pom.xml file of plugin:
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>2.0.40</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.0.40</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>4.5.0</version>
<dependencies>
<dependency>
<groupId>com.googlecode.totallylazy</groupId>
<artifactId>totallylazy</artifactId>
<version>1.20</version>
<scope>system</scope>
<systemPath>${basedir}/externalMavenLibrary/totallylazy-1.20.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber-jvm-example</projectName>
<outputDirectory>${basedir}/target/site/cucumber-pretty</outputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
<classificationFiles>
<param>**/*.properties</param>
</classificationFiles>
<cucumberOutput>${basedir}/target/cucumber.json</cucumberOutput>
<enableFlashCharts>true</enableFlashCharts>
<checkBuildResult>true</checkBuildResult>
<skippedFails>true</skippedFails>
</configuration>
</execution>
</executions>
</plugin>
Other versions in the pom.xml file:
serenity-cucumber: 1.9.35
serenity-rest-assured: 2.0.45
serenity-core: 2.0.45
serenity-junit: 2.2.1
serenity-maven-plugin: 2.0.40
Serenity.properties file:
serenity.project.name=Test
serenity.console.colors=true
serenity.reports.show.step.details=true
Since unable to get report after running mvn serenity:aggregate, missing graphs and other nice features.
Please guide.
Able to figure out the reason why the command was not working. in pom.xml file, after adding tags and while running the command by giving the report output path, I am able to get the Serenity reports as expected.
updates done:
serenity.test.root="com.projectname.backend.core"
serenity.reports.show.step.details=true
serenity.outputDirectory = target/site/reports
in pom.xml file: added tags configuration, and the tag has value in RunnerFile.java
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<configuration>
<tags>${tags}</tags>
</configuration>
Also, below dependency versions used:
<properties>
<serenity.version>2.2.1</serenity.version>
<serenity.cucumber.version>2.2.0</serenity.cucumber.version>
<serenity.maven.version>2.2.1</serenity.maven.version>
</properties>
Command used:
mvn serenity:aggregate -Dserenity.outputDirectory=C:\Users\projectname\target\site\reports
I encoutred this problem and my error was that I forgot to name scenario in the feature file. So check this part

maven-dependency-plugin:unpack Error

I'm trying to extract some .exe files from a dependency jar file and put them under ${project.build.directory}/classes/.
But when I execute:
mvn clean compile dependency:unpack
I get:
Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack (default-cli) on project simple: Either artifact or artifactItems is required -> [Help 1
I have verified that the dependencies are available in my local repository.
In my example pom below I've used junit as an example, but no matter which dependency I list, I get the same error.
pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes/externaltools</outputDirectory>
<includes>**/*.txt</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
The issue is due to you cannot use mvn clean compile dependency:unpack and <executions> tags together.
In documentation Maven Depdendency Plugin at the bottom part of the page you can read:
If you intend to configure this mojo for execution on the command line using: mvn dependency:unpack you must not put the configuration inside the executions tag. Your configuration should look like this:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
<includes>[ comma separated list of file filters ]</includes>
<excludes>[ comma separated list of file filters ]</excludes>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
I have tried removing the <execution> tags and works perfectly!

Maven generate javadoc for one submodule

I have a maven project with submodules.
Is is it possible to run on the root pom:
mvn clean install javadoc:javadoc
And building all the project (submodules) but generating the javadoc only for one of the submodule ? Cause I'm only interesseted to publish the javadoc of one.
My pom.xml contains the maven-javadoc-plugin.
Thanks.
Configure the Javadoc plugin within the module you want to have the javadoc generated:
<build>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>javadoc-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
[...]
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
This config will create the Javadoc each tome you call mvn package or mvn install

Maven: Overview for the values of Maven properties

I would like to find out the values of all Maven properties as they apply to some Maven project.
mvn help:system lists OS environment variables and JVM system properties, but no Maven properties.
mvn help:evaluate only works in an interactive mode, that means I have to type a single Maven property, (e.g. ${project.build.outputDirectory}) to get the value of that property.
I'm looking for a way get a full list of all Maven properties and their values.
As a workaround, add this to the <plugins> ... </plugins> section inside your project's pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Now execute mvn validate.
On the console, prefixed with [echoproperties], there will be the full list of system properties, including those set by Maven such as project.build.outputDirectory, basedir, and settings.localRepository.
the maven-help-plugin does what you want, just call it with -Dexpression=project.properties this will print the properties tag of the effective pom.
mvn help:evaluate -Dexpression=project.properties
Bonus Points when you just want the properties output and not the maven output
mvn help:evaluate -Dexpression=project.properties -q -DforceStdout
or with the explicit version because -DforceStdout works since version 3.1.0
mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.properties -q -DforceStdout
Not sure if helps, but I found this when trying to do the same thing:
mvn com.github.ekryd.echo-maven-plugin:echo-maven-plugin:echo -Decho.message='${project.build.testOutputDirectory}'
From here.
Adding the following to ${user.home}/.m2/settings.xml:
<pluginGroups>
<pluginGroup>com.github.ekryd.echo-maven-plugin</pluginGroup>
</pluginGroups>
the command can be shortened to:
mvn echo:echo -Decho.message='${project.build.testOutputDirectory}'
I don't know how to get them "officially", but here is a workaround. Add maven-antrun-plugin to your project and run mvn test -X. The plugin will show all properties passed to it from Maven. The list looks complete to me.
Actually project.build.outputDirectory is there but you need to execute in 'compile' phase, and NOT in 'validate'. I guess what properties are available also depends on the current phase for the executing goal of a particular plug-in, in this case 'maven-antrun-plugin'.
<!-- Ant Run Plugin for debugging pom.xml and calling ant tasks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${ant.plugin.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Had the same issue. Changed the timeout and maxheap in findbugs configuration through maven.
The below fixed it for me :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<maxHeap>2048</maxHeap>
<timeout>1800000</timeout>
</configuration>
</plugin>

gmaven grails project not using maven-war-plugin

I'm having issues with a filtered context.xml file being packaged in a mvn grails:war execution.
I have it working when you do mvn war:war but doing that doesn't create my grails application war. When running mvn grails:war I don't get the context.xml file. Is this a case of the grails:war target not running the maven-war-plugin? I'm getting no errors. Any help is appreciated. Here are my relevant pom settings:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>**/context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.3.4</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
...
<filters>
<filter>${basedir}/src/main/filters/dev.properties</filter>
</filters>
grails:war uses grails command so generate war, so it will ignore anything you configured in the "maven war plugin". You will have to configure it within grails.

Resources