🗜️Setting Up Maven Project in IntelliJ IDEA

New Project

  • Open IntelliJ IDEA and select "New Project."

  • Enter your project's name and other details.

  • Choose a project location

  • Choose "Maven" from the left-hand side and click "Create."

Dependency

  • Open the pom.xml file in your project.

  • Add any necessary dependencies in the <dependencies> section.

  • Save the file to automatically download the dependencies.

Plugins

Add below plugin to the pom.xml:

  • Add Compiler plugin to compile the framework.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.1</version>
        <configuration>
            <compilerArgument>-parameters</compilerArgument>
            <parameters>true</parameters>
            <testCompilerArgument>-parameters</testCompilerArgument>
        </configuration>
    </plugin>
  • Add exec-maven plugin to generate custom TestNg file as per the platform selected in automation configuration

    <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
             <execution>
               <goals>
                 <goal>java</goal>
                </goals>
             </execution>
            </executions>
            <configuration>
              <mainClass>in.precisiontestautomation.runner.ScriptlessApplication</mainClass>
                <arguments>
                  <argument>true</argument>
                </arguments>
            </configuration>
    </plugin>
  • Add maven-surefire-plugin to execute generated TestNg file through maven command mvn test

     <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>3.0.0-M4</version>
           <configuration>
              <argLine>-XX:+ExplicitGInvokesConcurrent</argLine>
              <argLine>--add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
              <testFailureIgnore>false</testFailureIgnore>
                <suiteXmlFiles>
                   <suiteXmlFile>target/testngenerator.xml</suiteXmlFile>
                </suiteXmlFiles>
           </configuration>
      </plugin>

Conclusion

After add above configuration in pom.xml, it will look like below

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.Test</groupId>
    <artifactId>SampleTestProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.precissiontestautomaton</groupId>
            <artifactId>ScriptLess-Automation</artifactId>
            <version>LATEST</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>${basedir}/src/main</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <compilerArgument>-parameters</compilerArgument>
                    <parameters>true</parameters>
                    <testCompilerArgument>-parameters</testCompilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>in.precisiontestautomation.runner.ScriptlessApplication</mainClass>
                    <arguments>
                       <argument>true</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <argLine>-XX:+ExplicitGInvokesConcurrent</argLine>
                    <argLine>--add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
                    <testFailureIgnore>false</testFailureIgnore>
                    <suiteXmlFiles>
                        <suiteXmlFile>target/testngenerator.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Last updated

Was this helpful?