Executing JQAssistant with maven in a project with submodules with profiles - maven

As the title shows i am using jqassistant with Maven. So far that worked well for small projects. Now i am using a project with multiple poms. As the guide tells (http://buschmais.github.io/jqassistant/doc/1.2.0/#_maven_plugin) i am only having this profile in the root-pom currently:
<profiles>
<profile>
<id>jqassistant</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<goals>
<goal>scan</goal>
<goal>analyze</goal>
</goals>
<configuration>
<failOnViolations>true</failOnViolations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.2.0</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</profile>
</profiles>
I also tried using the command useExecutionRootAsProjectRoot
However the build never scans the whole project.
Subpoms have other profiles. Do i need the profile in every pom? Do i need to declare dependencies to jQA? Where - only in the parent pom?

Related

providing cucumber test report name through maven command

In my pom.xml I have created different profile for smoke and regression test using cucumber framework. The using the below maven command to run the tests. Following is an example of smoke test:
mvn clean test -Psmoke-test -Dcucumber.options="--plugin html:target/cucumber/smoke-test-report.html"
The test is running fine, but it is not generating the report even if I provided the -Dcucumber.options I am using a common runner class for cucumber, so I cannot give the file name as part of the #CucumberOptions annotation.
Following is the pom.xml confguration:
<profile>
<id>smoke-test</id>
<properties>
<test>AutomationTestTrigger</test>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<spring.profiles.active>automation-test</spring.profiles.active>
<cucumber.filter.tags>#smokeTest</cucumber.filter.tags>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>regression-test</id>
<properties>
<test>AutomationTestTrigger</test>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<spring.profiles.active>automation-test</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Your POM should be like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.5.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>BDD-Automation</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<inputDirectory>${project.build.directory}</inputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
And command you can use like this:
mvn test -Dtest=Runner verify

Maven lost checkstyle config

I try to connect custom checkstyle.xml config instead standart sun_checks.xml to this project.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<configuration>
<configLocation>src/main/resources/checkstyle.xml</configLocation>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
But mvn -B clean verify checkstyle:checkstyle get output with sun_checks.xml
[INFO] There are 206 errors reported by Checkstyle 8.29 with sun_checks.xml ruleset.
Why <configLocation> is ignored, and hiw to fix it?
Hello #Pavel try to use checkstyle.xml outside your source code, and optionally set the goal also. It should solve your problem.
<properties>
<checkstyle.configLocation>src/checkstyle/checkstyle.xml</checkstyle.configLocation>
<checkstyle.suppressionsLocation>src/checkstyle/suppressions.xml</checkstyle.suppressionsLocation>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<!-- for java
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.26</version>
</dependency>
</dependencies>
-->
<configuration>
<configLocation>${checkstyle.configLocation}</configLocation>
<suppressionsLocation>${checkstyle.suppressionsLocation}</suppressionsLocation>
<sourceDirectories>
<sourceDirectory>src/main/java</sourceDirectory>
<sourceDirectory>src/test/java</sourceDirectory>
</sourceDirectories>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
A solution is starting maven task with the config location argument:
mvn checkstyle:check -Dcheckstyle.config.location=checkstyle.xml

How rerun failed test cases of cucumber-jvm in jenkins

How to rerun failed test cases of cucumber-jvm in jenkins?
According to answers mentioned in this thread:
How to rerun failed test cases in cucumber-jvm?
There is different maven command to move and run scenarios for rerun.txt. How to execute them in Jenkins with separate maven command for rerun?
I use cucumber-serenity framework, which uses cucumber-jvm in the background to run everything. Here are the relevant parts of my pom.
I have everything in a separate project, not mixed with any other code. If this is not your case, the following might break your build!
I turn off unit tests:
<build>
<plugins>
<!-- no unit tests: skip anything named *Test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
This does not relate to your question, but I manage all my selenium browser drivers with:
<!-- docs: https://ardesco.lazerycode.com/testing/webdriver/2012/08/12/introducing-the-driver-binary-downloader-maven-plugin-for-selenium.html -->
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver-binary-downloader.plugin.version}</version>
<configuration>
<rootStandaloneServerDirectory>${project.basedir}/selenium/bin</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/selenium/zip</downloadedZipFileDirectory>
<customRepositoryMap>${project.basedir}/RepositoryMap.xml</customRepositoryMap>
<overwriteFilesThatExist>true</overwriteFilesThatExist>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
I use the failsafe-plugin to run my integration tests:
<!-- integration tests: run everything named *IT -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<systemPropertyVariables>
<!-- set by driver-binary-downloader-maven-plugin -->
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above will not rerun any failed tests, which is what you probably want when you run stuff locally on your machine.
On Jenkins only, I turn on the rerunning of failed tests:
<profiles>
<profile>
<id>jenkins</id>
<activation>
<property>
<name>env.JENKINS_HOME</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<dependencies>
<!-- docs: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.plugin.version}</version>
</dependency>
</dependencies>
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I pasted the following in my Pom.xml file and I do not see any failed test case rerunning in Jenkins. Can you explain how to configure this Jenkins please
<profiles>
<profile>
<id>jenkins</id>
<activation>
<property>
<name>env.JENKINS_HOME</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<dependencies>
<!-- docs: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Running two maven profiles

My profiles in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>test-output</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>runWithHead</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>execution1</id>
<configuration>
<systemPropertyVariables>
<homepage>${ADDRESS}</homepage>
<head>true</head>
<browsers>${browser}</browsers>
<chromeDriverLocation>${chromeDriver}</chromeDriverLocation>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>runHeadlessly</id>
<properties>
<displayProps>target/selenium/display.properties</displayProps>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xvfb</id>
<phase>test-compile</phase>
<goals>
<goal>xvfb</goal>
</goals>
<configuration>
<browsers>${browser}</browsers>
<displayPropertiesFile>${displayProps}</displayPropertiesFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>execution2</id>
<configuration>
<systemPropertyVariables>
<homepage>${ADDRESS}</homepage>
<head>false</head>
<display.props>${displayProps}</display.props>
<browsers>${browser}</browsers>
<chromeDriverLocation>${chromeDriver}</chromeDriverLocation>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
So first we have got shared plugins and then two different profiles.
When i try to run them with one command
mvn clean install -P runHeadlessly,runWithHead
Only plugin with xvfb id gets executed, any ideas?
(did not post the part with default property variables)
You have defined two profiles:
First profile, runWithHead, defines an execution of the maven-surefire-plugin without specifying any goal element (within a goals section), hence an empty execution
Second profile, runHeadlessly, defines an execution and goal of the selenium-maven-plugin plugin AND again an empty execution of the maven-surefire-plugin
As such, both profiles are executed, but effectively only the xvfb of the xvfb execution of the selenium-maven-plugin would be performed.
Since the maven-surefire-plugin has only one goal, test, try to add the following to both executions:
<goals>
<goal>test</goal>
<goals>
Also note: you are configuring additional executions of the maven-surefire-plugin on top of the default default-test execution which will also be executed. Hence, enabling both profiles you will end up with three executions of this plugin.

Automatically bumping up pom.xml with Maven release plugin

I am playing with the Maven release plugin and I am trying to bump up the pom.xml version automatically. I noticed when I do:
mvn --batch-mode release:prepare
it will automatically bump up the z version, i.e. if it is x.y.z it will be x.y.(z+1). Is there a way to bump up the y or x version without having to specify before hand what those versions should be?
I stumbled upon some blogposts on how to achieve this, and made this maven-setup which makes it possible to specify if you want to do a major, minor or patch-release:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.build.helper.plugin.version}</version>
<executions>
<execution>
<id>parse-versions-for-release</id>
<phase>initialize</phase>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>major</id>
<activation>
<property>
<name>major</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>#{project.artifactId}-#{project.version}</tagNameFormat>
<useReleaseProfile>false</useReleaseProfile>
<releaseVersion>${parsedVersion.nextMajorVersion}.0.0</releaseVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>minor</id>
<activation>
<property>
<name>minor</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>#{project.artifactId}-#{project.version}</tagNameFormat>
<useReleaseProfile>false</useReleaseProfile>
<releaseVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0</releaseVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Here we use the build-helper-maven-plugin to figure out what the current (and next) version is, and we use maven profiles to specify if we want to do a major, minor or patch (default) release.
Source code can be found here: https://github.com/mortenberg80/maven-release-example
The blog posts I got inspired from were:
https://thihenos.medium.com/maven-release-plugin-a-simple-example-of-package-management-9926506acfb9
Maven release: next development version in batch mode

Resources