1

I am trying to executing a powershell script that writes to a file during a maven build.

I am invoking the build with mvn clean install through Eclipse IDE.

This is the plugin in my pom.xml:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>${project.basedir}/.my-file.ps1</executable>
            </configuration>
        </plugin>
    </plugins>

The powershell script is a hidden file so that's why I have a . in front of the file name.

However, the plugin is not executing and I am following the instructions in the official documentation.

Kingamere
  • 9,496
  • 23
  • 71
  • 110
  • Maybe the executable is actually `powershell.exe` and the script is an argument. – brendan62269 Oct 31 '17 at 18:29
  • @brendan62269 The *plugin itself* isn't even running; the plugin isn't starting. If it actually did start and tried running, I would get some sort of output saying whether the powershell script was executed or not. But the *plugin itself* isn't executing. – Kingamere Oct 31 '17 at 18:32

1 Answers1

3

You are running mvn clean install which will go through various build phases, but your exec plugin execution is not attached to any phase. You'll have to either:

Attach your execution to a phase by adding the <phase> element to your execution, for example to attach it to the pre-integration-test phase:

   <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
            <execution>
                <id>my-exec</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>${project.basedir}/.my-file.ps1</executable>
        </configuration>
    </plugin>

Or call specifically the exec goal using mvn exec:exec command.

If you are not familiar with the Maven lifecycle and various phases of a build, read the Introduction to the Build Lifecycle guide, or specifically the Plugins part to learn more about plugins executions and phases attachment.

Pierre B.
  • 11,612
  • 1
  • 37
  • 58
  • Thanks, this worked. But how the plugin documentation here http://www.mojohaus.org/exec-maven-plugin/usage.html doesn't even mention use of the element? Some plugins' goals bind to a certain phase by default, and don't need the phase element, so I thought this applies for this plugin, but guess not. Even this isn't stated in the documentation. – Kingamere Nov 01 '17 at 20:12
  • 1
    You're welcome :) Usually a plugin doc mentions if it has a default phase binding (such as the Surefire Plugin). If not, assume it does not bind to any phase by default. Plugin config is one of the main concept of build lifecycle. Though not very well put into evidence for Maven beginners, doc can be found right after the Getting Started at: https://maven.apache.org/pom.html#Plugins, and the default plugin binding is a little hidden: http://maven.apache.org/ref/3.2.2/maven-core/default-bindings.html. I agree it may be a good idea to introduce these concepts earlier in the doc. – Pierre B. Nov 02 '17 at 08:58