Maven command runs fine on local machine, but not in Jenkins - java

So I have a maven project that has a profile
When I run the following in the terminal for my project, the tests will run just fine
mvn clean install -Pserial-integration-test -Dcucumber.options="--tags #'QR_Scan'" -Dtest.environment=PrePRod
When I run the following in a Jenkins project it will not run the tests that I need it too
clean install -Pserial-integration-test -Dcucumber.options="--tags #'QR_Scan'" -Dtest.environment=PrePRod
Jenkins settings
I have setup a Jenkins Maven project and told Jenkins where my Pom is, and I send the command below for the goal and options "clean install -Pserial-integration-test -Dcucumber.options="--tags #'QR_Scan'" -Dtest.environment=PrePRod"
Maven Settings
serial-integration-test
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<junitPlatformArtifactName>com.github.junit-team.junit5:junit-platform-engine</junitPlatformArtifactName>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.class</include>
</includes>
<systemPropertyVariables>
<test.environment></test.environment>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<plugins>
<plugin>
<name>com.gm.onstar.rita.cucumber.CucumberReporter</name>
</plugin>
</plugins>
<glue>
<package>com.gm.onstar.rita.stepdefinitions</package>
</glue>
<featuresDirectory>src/main/resources/features</featuresDirectory>
<tags>
<tag>${cucumber.tag1}</tag>
<tag>${cucumber.tag2}</tag>
<tag>${cucumber.tag3}</tag>
<tag>${cucumber.tag4}</tag>
<tag>${cucumber.tag5}</tag>
<tag>~#Ignore</tag>
</tags>
</configuration>
</execution>
</executions>
</plugin>
What I have tried
I have tried putting in like this in Jenkins -Dcucumber.options="--tags #QR_Scan" and like this -Dcucumber.options='--tags #QR_Scan'
I have tried putting the profile -Pserial-integration-test with a space and without a space -P serial-integration-test
I have tried to see if I a missing some sort of plugin
I have tried to see if Mvn clean install or Mvn clear verify would run it on Jenkins
What it might be.
Jenkins does not like that my cucumber runner is in the main and not in java test folder?
Am I missing a plugin for Jenkins?
Am I typing the command in wrong in jenkins, and maybe missing some parentheses or something?
Any help would be appreciated. Thank you!

Related

How to run java program using Maven

I am trying to run a Java project using Maven, need help on how to run
I tried with various options, Run As > Maven clean, Run As > Maven Install, Run As > Maven test, etc.
But the output is not showing in the console though build is successful
I am using eclipse and able to run java file using Run As > Java Application
My Build tag in pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>mypackage.classnamehavingmain</mainClass>
</configuration>
</plugin>
</plugins>
</build>
You should add the goal for execution
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>your_goal_name</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
and then to execute you can perform :
mvn exec:your_goal_name
If you would like to run it from the terminal you can do mvn compile exec:java -Dexec.mainClass=mypackage.classnamehavingmain.

maven-surefire-plugin how to rerun failed TestNG tests? There is default rerun option for JUnit only

How can I run the failed TestNG tests with maven failsafe plugin?
I run my tests with 'mvn clean install'.
When I run the tests and I get failing tests, I need to rerun them.
I do not have a testng.xml file and I think that this is also an issue.
This my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
<systemProperties>
<browser>${browser}</browser>
<screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
<remoteDriver>${remote}</remoteDriver>
<gridURL>${seleniumGridURL}</gridURL>
<desiredPlatform>${platform}</desiredPlatform>
<desiredBrowserVersion>${browserVersion}</desiredBrowserVersion> <!--Set properties passed in by the driver binary downloader-->
<!--Set properties passed in by the driver binary downloader-->
<phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
</systemProperties>
<includes>
<!-- All that is left now is to clean up the code in our basicTest class and change its name to BasicTestWD. You may have noticed that we added an <includes> configuration item to our POM. This is because Maven will use maven-surefireplugin to run files that have test at the start or end of their name. We don't want maven-surefire-plugin to pick up our tests; we want to use maven-failsafeplugin instead. -->
<include>**/*WD.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<rootStandaloneServerDirectory>
${project.basedir}/src/test/resources/selenium_standalone_binaries
</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips
</downloadedZipFileDirectory>
<customRepositoryMap>${project.basedir}/src/test/resources/RepositoryMap.xml
</customRepositoryMap>
<overwriteFilesThatExist>${overwrite.binaries}</overwriteFilesThatExist>
</configuration>
<executions>
<execution>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven How to show warnings of codes when compiling

I'm using maven to build a new project. There are some warnings in my codes which are underlined by yellow line. I wish maven could report these warnings in console. How can I accomplish that? Can I just add some parameters in the command such as mvn -XXX clean compile?
<showDeprecation>
Sets whether to show source locations where deprecated APIs are used.
Default value is: false
User property is: maven.compiler.showDeprecation
<showWarnings>
Set to true to show compilation warnings.
Default value is: false
User property is: maven.compiler.showWarnings
-- Maven Doku
As simple as mvn clean install -Dmaven.compiler.showDeprecation=true -Dmaven.compiler.showWarnings=true all in one line.
You could even remove the =true part because, when you add a maven parameter with -D it automatically sets its value to true, if not set to something else.
With maven 3.3.9, using the maven-compiler-plugin and Java 1.8, you need a <configuration> section like the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
I got this answer from here when none of the above worked for me: http://frequal.com/java/EnableWarningsInMaven.html
I am guessing you are using the compiler plugin. Have you tried this?
Use the maven compiler plugin in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
To get to see detailed logs in maven you can use the command line option
-X, --debug Produce execution debug output
e.g this can be used as
mvn clean install -X
Also if what you want to get in the logs is the compiler warnings (The value of the local variable a is not used). You can try modifying your project's pom.xml with the following -
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
... other plugins
</plugins>
</build>

How to have specific maven goal appear on Life-cycle or plugins without run configuration

I have a maven project, in my pom.xml file, I'm using org.codehaus.mojo
I have generated an option to run the main class with a synonym name:
mvn exec:java#genSql
mvn exec:java#runSql
I would like these goals to appear under Maven LifeCycle/Plugins just like Clean, instal, etc.
I don't want to use Maven run configuration since it's not on git
How do make it shown on the Lifecycle or Plugins?
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>genSql</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.myCompany.build.SqlGenerator</mainClass>
</configuration>
</execution>
<execution>
<id>runSql</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.myCompany.build.DBLauncher</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Deploy Java app to Heroku using Git

My project written using the Spark framework has this build config.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.7</compilerVersion>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.avaje</groupId>
<artifactId>ebean-maven-enhancement-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>main</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<configuration>
<classSource>target/classes</classSource>
<packages>somepath.domain.**</packages>
<transformArgs>debug=1</transformArgs>
</configuration>
</plugin>
</plugins>
</build>
Its main class resides in somepath.Bootstrap.
The Procfile sits next to the pom.
What should the contents of the Procfile be?
(I am deploying via git.)
Procfile contains command, that will be executed after deploying your appliaction (git push heroku master for you example i guess).
I do not very familiar with spark, but i guess it can be something like this:
web: mvn exec:java -Dexec.mainClass="somepath.Bootstrap"
A Procfile is a mechanism for declaring what commands are run by your application’s dynos on the Heroku platform.
Here is an example for a Java app:
web: java -cp target/classes:target/dependency/* Main
This is taken from a Heroku Java sample app that uses Spark.
Be aware that build tools, such as Maven, will not be available at runtime.

Categories