Search code examples
mavenpowershellmaven-3pom.xml

execute windows powershell script using pom.xml


I want to execute windows powershell script with Maven. Here is what I tried:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
        <execution>
            <id>some-execution</id>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>D:\Projects\test.ps1</executable>
    </configuration>
</plugin>

But it is just opening the powershell script while executing the pom

mvn exec:exec

Solution

  • Doesn't got any other option so write below line in batch file

    PowerShell -NoProfile -ExecutionPolicy unrestricted -Command D:\Projects\Test.ps1
    

    and use the exec plugin to call the batch file, which will execute the powershell script.

    Like

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1.1</version>
        <executions>
            <execution>
                <id>some-execution</id>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>D:\Projects\test1.bat</executable>
        </configuration>
    </plugin>