# 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."

  <figure><img src="/files/QQ8CmqzP9hkCfncU1rS0" alt=""><figcaption></figcaption></figure>

### **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.

  <figure><img src="/files/s58znPkGeBzICEKEv8qR" alt=""><figcaption></figcaption></figure>

### Plugins

Add below plugin to the pom.xml:

* Add Compiler plugin to compile the framework.<br>

  ```
  <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<br>

  <pre><code><strong>&#x3C;plugin>
  </strong>        &#x3C;groupId>org.codehaus.mojo&#x3C;/groupId>
          &#x3C;artifactId>exec-maven-plugin&#x3C;/artifactId>
          &#x3C;version>3.1.0&#x3C;/version>
          &#x3C;executions>
           &#x3C;execution>
             &#x3C;goals>
               &#x3C;goal>java&#x3C;/goal>
              &#x3C;/goals>
           &#x3C;/execution>
          &#x3C;/executions>
          &#x3C;configuration>
            &#x3C;mainClass>in.precisiontestautomation.runner.ScriptlessApplication&#x3C;/mainClass>
              &#x3C;arguments>
                &#x3C;argument>true&#x3C;/argument>
              &#x3C;/arguments>
          &#x3C;/configuration>
  &#x3C;/plugin>
  </code></pre>
* 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>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.precisiontestautomation.in/scriptlessautomation/get-started/setting-up-maven-project-in-intellij-idea.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
