Tool stack :– Intellij (IDE) + Gradle (Build tool) + TestNg (Testing framework)
Step1:– Create a basic java class to display “HelloBuild!”, execution using TestNG.
Step2:-Browse to the parent directory of the java class using Terminal/Command prompt > gradle clean
This is used to clean any existing build directory (cleaning everything including leftovers from previous builds which are no longer relevant. )
Step3:- gradle build, build the java projects and create the JAR package inside build > libs > test-****.jar
Step4:- Now our jar package is ready lets browse to this package and try to run the java class
java – jar test-****.jar
This failed with “no main manifest…”
Step5:-add the below line to your build.gradle
Main-Class : ‘Name of the class to be build‘
Step6.:- if we repeat step2 > step 4 again, this time, you will get the “no main method error” as below. As our code doesn’t contain any main method to start the execution.
Step7:- Here comes the final solution…Adding the below code inside our main method in the “TestBuild” class and add the testng.xml file containing the TestBuild class name as below.
Now repeat the build process above, this time it will execute the code and print the “HelloBuild!”
WOOW WE MADE IT 🙂