Issue
Is it possible to conditionally run a maven plugin only if a specific directory doesn't exist?
I'm essentially trying to prevent npm ci
from running unnecessarily as package.json rarely changes. So ideally it would only run when node_modules
doesn't exists.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>npm-install</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>ci</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Solution
You can wrap it into a profile and activate that profile only if a given file does not exist.
Answered By - J Fabian Meier
Answer Checked By - David Goodson (JavaFixing Volunteer)