Maven: Overview for the values of Maven properties - maven-3

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>

Related

Cucumber : Setting setSkippedAsNotFailing is not working when I am running from jenkins

Below are my Jenkins setup:
Created Freestyle project
In Build section added :- Invoke top-level Maven targets In
In Post-Build Actions added:- Cucumber reports
However the same is working fine when I am executing from maven. here is the pom.xml setting related to cucumber reports.
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Sample</projectName>
<skip>false</skip>
<outputDirectory>${project.build.directory}/cucumber-reports</outputDirectory>
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory>
<buildNumber>2</buildNumber>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
<classificationDirectory>${project.build.directory}/cucumber-reports</classificationDirectory>
<classificationFiles>
<param>*.properties</param>
</classificationFiles>
<checkBuildResult>false</checkBuildResult>
<setSkippedAsNotFailing>true</setSkippedAsNotFailing>
<treatPendingAsFailed>false</treatPendingAsFailed>
<treatUndefinedAsFailed>false</treatUndefinedAsFailed>
</configuration>
</execution>
</executions>
</plugin>
Please let ne know what I am missing..
Unfortunately, cucumber-reports-plugin does not have a setting for its own notFailingStatuses parameter(aka setSkippedAsNotFailing in pom) from cucumber-reporting library.
I have forked the plugin and made some changes to enable that setting. You can check it out here and build a custom plugin yourself.

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(pom.xml) do not run a plugin during deploy/install phase

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.

How to use Atlassian Bamboo variables in Maven pom.xml?

I want to use Atlassian Bamboo to deploy non-Maven artifacts, that is artifacts created outside of Maven in another Bamboo task. So I created a Maven 3.x task and put it after the task that creates the artifacts and put deploy:deploy-file in the Goal box. The goal configuration requires the full path of the file I want to deploy. So I did this...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy-my_artifact-tgz</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<!-- Will this work??? -->
<file>${bamboo.build.working.directory}/dist/my_artifact.tgz</file>
<url>${project.repoUrl}</url>
<repositoryId>${project.repoId}</repositoryId>
<groupId>${project.groupId}.rtim.garner</groupId>
<version>${project.version}</version>
<artifactId>my_artifact</artifactId>
<packaging>tgz</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Can I use the ${bamboo.build.working.directory} to define part of the file path inside the part of the , as I have above? Should I expect Bamboo to substitute this to the correct value?
NOTE: Showing the effective pom in the Bamboo job does not substitute the varables' corresponding value so I can't tell.
I had to pass it the value of the variable. So I have this in my Goal text box of my Bamboo Maven task.
-Dbamboo.build.working.directory=${bamboo.build.working.directory} deploy:deploy-file

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

Resources