How to configure maven-release to use Perforce as SCM provider? - maven

I am trying to use the maven release plugin to create a released version of a Java project having Perforce as the SCM.
My pom scm section is:
<scm>
<connection>scm:p4:myperforcehostname:1666://mydepot/mycomponent</connection>
<developerConnection>scm:p4:myperforcehostname:1666://mydepot/mycomponent</developerConnection>
<url>http://myperforcehostname:1666</url>
</scm>
Also I use the P4Maven plugin and the Maven Release Plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>com.perforce</groupId>
<artifactId>p4maven</artifactId>
<version>[2011,2012)</version>
</dependency>
</dependencies>
<configuration>
<connectionType>connection</connectionType>
<username>myusernme</username>
<password>mypassword</password>
<includes>**</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
</plugin>
When calling 'mvn release:prepare -DdryRun=true' I get
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:prepare
(default-cli) on project mycomponent: The provider given in the SCM URL could not be found:
No such provider: 'p4'. -> [Help 1]
Any ideas?
I am able to call mvn scm:checkout.

You need to add the p4maven as dependency to the maven-scm-plugin as well as to the maven-release-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>com.perforce</groupId>
<artifactId>p4maven</artifactId>
<version>[2011,2012)</version>
</dependency>
</dependencies>
<configuration>
<connectionType>connection</connectionType>
<username>username</username>
<password>password</password>
<includes>**</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
<dependencies>
<!-- P4Maven -->
<dependency>
<groupId>com.perforce</groupId>
<artifactId>p4maven</artifactId>
<version>[2011,2012)</version>
</dependency>
</dependencies>
<configuration>
<connectionType>connection</connectionType>
<username>username</username>
<password>password</password>
<includes>**</includes>
</configuration>
</plugin>

It turned out that P4Maven comes not out of the box. I had to download it from the Perforce pages and install it into my repository (following the instructions in the download zip file). After that I could successfully use p4 as the SCM provider.

Here I done recently:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<dependencies>
<dependency>
<groupId>com.perforce.p4maven</groupId>
<artifactId>p4maven-provider</artifactId>
<version>1.0.6</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<dependencies>
<dependency>
<groupId>com.perforce.p4maven</groupId>
<artifactId>p4maven-provider</artifactId>
<version>1.0.6</version>
</dependency>
</dependencies>
</plugin>
And then some useful commands:
mvn scm:changelog -Dusername=yourP4user -Dpassword=yourP4pwd
release:prepare -Dusername=yourP4user -Dpassword=yourP4pwd -autoVersionSubmodules=true -DignoreSnapshots=true

Related

Using Provided Artifact As Maven Plugin Dependency

This seems like it should be a simple question, but I can't seem to find any information about it. When a maven plugin has a required dependency, is it possible to tell it to use an artifact defined elsewhere in the section of the pom?
As an example, I'm trying to add the 'maven-processor-plugin' to my build. That plugin has a dependency on 'hibernate-jpamodelgen'. I'm working with wildfly, so I already have that jar as a dependency of the project. I want to ensure I am using the same version for both. Is what I'm trying to do even possible?
Some code snippets:
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb3</artifactId>
<version>${version.server.bom}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<processor>-proc:none</processor>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/java/jpametamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<!-- How do I handle this without hard coding the version? -->
<!-- <version>???</version> -->
</dependency>
</dependencies>
</plugin>
</build>
Define a property like <hibernate-jpamodelgen.version> in the <properties> section of the POM.
Then use that property for the version like ${hibernate-jpamodelgen.version}.

Can we execute multiple profiles in the same pom.xml file

I have created a Maven project in Eclipse and have 2 xml files in it. I have created 2 profiles "TestNG.xml" and "TestNG2.xml" in the pom.xml file for my Maven project.
I ran the following command from command prompt
- mvn test
Expected behavior : TCs under both the TestNG.xml and TestNG2.xml files should get executed.
Actual behavior : Only TCs under TestNG2.xml file is getting executed.
NOTE :- When i am executing the .xml files individually using the below command it works fine{TestNG.xml file has been profiled as Regression in the pom.xml file}
- mvn test -PRegression
Below is the snapshot of my code from pom.xml file
<groupId>Rohit</groupId>
<artifactId>MavenProject05202020</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenProject05202020</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>Regression</id>
<!-- Below is MAVEN SURE FIRE PLUGIN. This will help to execute all your TCs present in your test folder{i.e.:-src/test/java}-->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<!-- Below is MAVEN SURE FIRE PLUGIN.
<profile>
<id>Smoke</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng2.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- below is the dependency for Selenium project -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<!-- Below is the dependency for TESTNG. -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<!-- Below is the dependency for RestAPITest project -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
If you just define the surefire-plugin twice, these definitions will override each other.
Instead, you need to define an <execution> in the plugin declaration and bind it to a phase. Plugins can have more than one execution in the <executions> block.

Maven skip generating reports when executing Maven build

I have several reporting plugins defined in the project and when I do Maven → build fails with FileNotFoundException as the reports are cleared when I do Maven → clean. Is there a way to ignore reports when doing Maven build so that build passes without any issue? I tried using Surefire plugin but not luck.
My pom.xml looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<skip>${maven-site-plugin.skip}</skip>
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
</reporting>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.2.0</version>
</dependency>
For maven-surefire
add after version
<configuration>
<skipTests>true</skipTests>
</configuration>
I got the fix for this now. I updated selenium version to 3.14 and I see no issue when building the project

Running "mvn test site" giving [ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project

I'm trying to generate xslt report using reporty-ng with Testng+maven but getting error as
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project Selenium Project: failed to get report for org.reportyng:reporty-ng: Plugin org.reportyng:reporty-ng:1.2 or one of its dependencies could not be resolved: Failure to find org.reportyng:reporty-ng:jar:1.2 in https://github.com/cosminaru/reporty-ng/raw/master/dist/maven was cached in the local repository, resolution will not be reattempted until the update interval of reporty-ng has elapsed or updates are forced -> [Help 1]
Below is the part of the pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<!-- TestNG-xslt related configuration. -->
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.2</version>
<configuration>
<!-- Output directory for the testng xslt report -->
<outputDir>/target/testng-xslt-report</outputDir>
<sortTestCaseLinks>true</sortTestCaseLinks>
<testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
<showRuntimeTotals>true</showRuntimeTotals>
</configuration>
</plugin>
</plugins>
</reporting>
<pluginRepositories>
<pluginRepository>
<id>reporty-ng</id>
<url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url>
</pluginRepository>
</pluginRepositories>
In my understanding of this, if you run "mvn clean verify", that will include the "site" phase of the build as well as the tests. You shouldn't need to explicitly call the site phase and so don't do it. Also, if you were to explicitly call the "site" phase, you should probably include the site plugin as a dependency, don't you think?
In my experience with both TestNG reports and ReportNG reports, the site plugin is not related to the report output. The site plugin is only related to the "Surefire" (or Failsafe) plugins reporting phase output. In other words, you will notice that the default output folder of Surefire plugin is directly related to the standard output location of "site" plugin, in general. This can be very confusing, I agree.
Also, I would configure it (possibly) like so:
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.4</version>
<configuration>
<outputDirectory>${project.build.directory}/surefire/reportng</outputDirectory>
<sortTestCaseLinks>true</sortTestCaseLinks>
<testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
<showRuntimeTotals>true</showRuntimeTotals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>${basedir}/target/site</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.9</version>
<configuration>
<outputDirectory>${basedir}/target/site</outputDirectory>
<reportsDirectories>
<reportsDirectories>${basedir}/target/surefire</reportsDirectories>
</reportsDirectories>
</configuration>
<reportSets>
<reportSet>
<id>integration-tests</id>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>

Maven - differences between dependencies inside plugin and outside?

I've come across some sample code which specifies dependencies inside the plugin tag like this :
<build>
<plugins>
<plugin>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
It look strange to me because mostly I see people put the dependencies tag outside the build tag.
When you add <dependency> to project it is available to that project depending on its scope (compile, test, runtime, etc)
But when you add <dependency> inside plugin's execution you are making that artifact available to that plugin in classpath at runtime
For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>check my sources</id>
<goals>
<goal>check</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
</plugin>
in this snippet checkstyle:checkstyle:4.4 is being available to maven-checkstyle-plugin at runtime
Read More
How to override a plugin's dependency in Maven

Resources