Run testng.xml from command prompt. I have jar that is created from Maven Project. Surefireplugin is not solving my purpose - maven

What i have
Jar created from maven project
TestNG.xml file
What i want
Want to run testng.xml from command prompt
What i tried
Used surefire plugin in pom then executed mvn test command.
What is problem then ?
Surefire plugin will need. src folder and every time it will build project.
Any solution available ? Using jar file and testng . I dont want to use src or bin

You could use a multi-module maven project.
For example with two modules, A and B. Module A will build the jar file, and in module B, you can specify A as a dependency, and run your tests from there.

Related

Setting name of jar file while using mvn install:install-file

So previously I was trying to find a way to install jar file which is built in my project to the .m2 folder via run configuration support.
Link for reference.
My main concern then was to not keep any hard coded values in command and to pick most data from pom.xml file. This was achieved successfully, but now I have another problem.
In the project, I have 2 modules module1 and module2.
When module1 is built, it generates 2 files a war file since it is a web based application and second one is jar file which is used to satisfy dependencies of other modules.
The jar file is generated using
<attachClasses>true</attachClasses>
property set in the maven-war-plugin in pom.xml of module1.
So if the module1 artifact id is set as module1-corp, then the jar file is named as module1-corp-classes.jar if the jar is installed using maven-install-plugin. But due to the legacy structure of the project, maven-install-plugin cannot be used and I have to use maven command line via Intellij run configurations to install this file.
So the command I used is
mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar
This installs the jar file perfectly, only it doesn't append the classes part at the end of jar file. so my jar file is now installed as module1-corp.jar instead of module1-corp-classes.jar which is not working okay with modules which are dependent on it.
I suspect this is due to the way module1 dependency is accessed in module2 which is as follows:
<dependency>
<groupId>module1.groupid</groupId>
<artifactId>module1.artifactId</artifactId>
<version>${module1.version}</version>
**<classifier>classes</classifier>**
</dependency>
This code is in the module2 pom.xml. I believe the classifier part is what is causing the issue, but I cannot change this since it is a legacy project.
So in the end I have two options only
Rename the jar while it is being installed via maven command line
Some other way which can rename the jar via an Intellij run configuration.
I tried using following flag
mvn install:install-file -Djar.finalName=jarname
But this doesn't seem to work as expected.
The install maven plugin allows also to specify the classifier (see: here). So in your example the command would need to be changed to:
mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar -Dclassifier=classes

Spotbugs maven plugin output in a single XML

I had run spotbugs using the spotbugs-maven-plugin and it creates an XML in target folder as spotbugsXml.xml when I run the command
mvn spotbugs:spotbugs
For multi-module projects, the project creates a target/spotbugsXml.xml for every module specified. Is there a way where I can get a single spotbugs xml in the parent build directory?

How to execute a maven goal described in a pom.xml file packaged in a jar

I have a maven project which generated a jar with its pom file inside and this jar is deployed on different environment. pretty straightfoward for the moment.
I would like to execute a goal (a liquibase:update) from this pom file using only the jar produced. Is there a way to do this automatically with maven, without extracting the files from the jar beforehand ? Something like mvn -jar myJar.jar liquibase:update
Check the answer to this question, I think it can help you:
Is there a good way to use maven to run an executable jar?

Gradle build not invoking JUnit

My gradle script for building an EAR is not running any JUnit tests I have. The command I used for invoking the script is
gradle build
I also tried
gradle test
and that also did not work.
My build structure is as follows
settings.gradle
gradle.properties
EARProject
build.gradle
META-INF
application.xml
lib
JARProject
build.gradle
src/main/java
....
src/test/java
....
WebProject
build.gradle
src/test/java
src/main/java
WebContent
.....
I am invoking the gradle command from EARPRoject directory.
What changes I need to do in order to run the test cases. Please note that if I run the gradle build command from individual projects it is working as expected.
Regards
-Albin
Apparently, EARProject doesn't have any tests. Depending on what you want, run gradle build from the top directory, or from a subproject/subdirectory containing tests. Alternatively, you can run gradle buildNeeded from EARProject, which will perform a full build of all projects that EARProject depends upon (which presumably includes JARProject and WebProject).

How to Tests for a specific module under a project in Jenkins through maven?

I use Jenkins to build my project which has multiple modules. This project has a root pom.xml which build all the modules under that project. I specify this pom.xml as the root POM.
Now I want to run tests as a "post-build step". But, I don't want to run all the tests under all modules. I want to run tests only under a specific module.
I tried using the shell command to change the directory to the module for which tests has to be run and then trigger maven. I also tried using the -f switch to specify the pom.xml for that particular module. Both of these steps are not working.
Please help me guys in resolving this problem.
Thanks
Just run from the root path:
mvn -pl :submodule test
protip: mvn --help

Resources