Execute sh script during build - maven

I have this plugin in pom.xml
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution><!-- Run our version calculation script -->
<id>Version Calculation</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${basedir}/target/process.properties</workingDirectory>
<executable>${basedir}/Scripts.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
Process.Properties file
link.item=true
link.process=false
link.process.run=Downloads_Item.txt$
Scripts.sh
#!/bin/bash
sed 's/Downloads_Item/Downloads_Item_NiteVate/g' Process.properties
I am trying to replace the value of the flag link.process.run by executing Scripts.sh.
I tried but its not worked. This should happen while taking build.
I am not able to find where is the problem

Related

Conditionally run a mvn plugin if a specific directory doesn't exist

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>
You can wrap it into a profile and activate that profile only if a given file does not exist.

Moving a resource in maven with wildcard

I was trying to move a file to an existing one with a variable (cache busted) part:
file.js should be copied over an existing file-0123456789abcdef.js (of which the last part 16 hex digits is variable)
The copy-rename-maven-plugin results in an extra file: file-*.js:
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<executions>
<execution>
<id>move-file</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/unpacked/file.js</sourceFile>
<destinationFile>${project.build.directory}/unpacked/file-*.js</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
I would like to end up with one file: file-0123456789abcdef.js with the content of file.js.
A simple terminal command can easily do what I want but I would like to avoid using the ant plugin.
Help will be much appreciated!
I found out that the exec-maven-plugin could do the trick in combination with a find -exec:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>move-configuration</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>find</executable>
<arguments>
<argument>${project.build.directory}/unpacked/>
<argument>-name</argument>
<argument>file-*.js</argument>
<argument>-exec</argument>
<argument>mv</argument>
<argument>${project.build.directory}/unpacked/file.js</argument>
<argument>{}</argument>
<argument>;</argument>
</arguments>
</configuration>
</plugin>

How to have exec-maven-plugin:exec run before 'site' phase?

I have this script I need to run before site phase to fix an issue (http://jira.codehaus.org/browse/MSITE-640).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<inherited>false</inherited>
<executions>
<execution>
<id>workaround-MSITE-640</id>
<!--it should be 'site' but maven doesn't pick up there-->
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<failWithEmptyArgument>false</failWithEmptyArgument>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>./workaround-MSITE-640.sh</executable>
<arguments>
<argument>${settings.localRepository}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
But I can't seem to run it on that phase. I tried to put it under reporting -> plugins but it can't have configuration there.
It is idempotent, so no problem in running it more than once, but would be nice if I could tie it to the correct phase.
Thanks

Failed to execute goal org.codehaus.mojo:exec-maven-plugin. Command execution failed

I have a maven project.To run cucumber test i have following configuration in my pom file.
<plugin>
<groupId>net.mynetwork</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<id>execution</id>
<phase>site</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.name}</projectName>
<outputDirectory>${project.build.directory}/site/cucumber-html-reports</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
<enableFlashCharts>false</enableFlashCharts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<arguments>
<argument>${host}</argument>
<argument>${port}</argument>
<argument>${profile}</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
When i am executing mvn command.
mvn clean install
its giving me following error.
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (cucumber) Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour.
Failed to execute goal net.mynetwork:maven-cucumber-reporting:0.0.4
Please suggest any solution and let me know if anything else needs to be share.
Looks like http://jira.codehaus.org/browse/MEXEC-104.
Try this instead:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<commandlineArgs>${host} ${port} ${profile}</commandlineArgs>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

how to execute multiple command prompt commands using maven in single pom.xml

I want to run multiple command prompt commands in maven using single pom.xml. How can I do that?
For ex: I have 2 commands to execute. I am executing the first command by using exec-maven-plugin.
Below is the portion of my pom.xml to execute the first command:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>load files</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<arguments>
<argument>wt.load.LoadFileSet</argument>
<argument>-file</argument>
<argument>${basedir}/fileSet.xml</argument>
<argument>-UNATTENDED</argument>
<argument>-NOSERVERSTOP</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
</configuration>
</plugin>
For this the build is success.
Is it possible to execute one more command just like above in the same pom.xml? I was not able to do that. So someone please help how to add it in pom.xml
The answer can be found in the FAQ.
The full answer is here: http://article.gmane.org/gmane.comp.java.maven-plugins.mojo.user/1307
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>id1</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd1</executable>
</configuration>
</execution>
<execution>
<id>id2</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd2</executable>
</configuration>
</execution>
</executions>
</plugin>
Then you specify execution ids as:
mvn exec:exec#id2
But this syntax is possible starting from maven 3.3.1

Resources