3

I have a bash script which I want maven to run after the compilation phase, since the script is supposed to deploy bundles. Here is the plugin I am trying to utilize in my release module:

<plugin>
          <artifactId>exec-maven-plugin</artifactId>
          <groupId>org.codehaus.mojo</groupId>
          <executions>
            <execution>
              <id>deploy-bundles</id>
              <phase>install</phase>
              <goals>
                <goal>exec</goal>
              </goals>
              <configuration>
                <executable>${basedir}/deploy.sh</executable>
              </configuration>
            </execution>
          </executions>
        </plugin>

I have the deploy.sh in the correct path, so that's verified. Now when I do mvn install I get the following error:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (deploy-bundles) on project module.release: Command execution failed. Cannot run program "/bla/bla/module.release/deploy.sh" (in directory "/bla/bla/module.release"): error=13, Permission denied -> [Help 1]

First, I thought it was about the bash script I wrote. So I changed it to a simple bash script like this:

#!/bin/bash          
STR="Hello World!"
echo $STR    

however, I got the same error. So it is not about the code. Should I given maven special rights? Should use the sudo command?

Schütze
  • 1,044
  • 5
  • 28
  • 48
  • 1
    The script must have the permission to be executed. exec-maven-plugin is not releated to that...You need to set execution attribute on linux `chmod +x deploy.sh` also you need to add that to your version control (git, subversion)... – khmarbaise Jul 15 '16 at 10:20
  • I want everything to be done with simple `mvn install` command, since the user should be dealing with `chmod` or such. Is there a way to tell maven to handle this? – Schütze Jul 15 '16 at 10:25
  • 1
    As i said you need to set the permission correctly and put that correctly into your version control...I don't know what you mean by `user should be..`? – khmarbaise Jul 15 '16 at 10:26
  • Sorry I read your message wrong, now I got it and it did work, thanks. If you write this as answer, I'll accept. – Schütze Jul 15 '16 at 10:34

2 Answers2

5

Getting file permissions stored in VCS might be tricky, not every VCS is good at that.

Instead you could execute /bin/bash with your script as an argument (and remove the #!... line from your script).

Your configuration could look like this:

<configuration>
    <executable>/bin/bash</executable>
    <arguments><argument>${basedir}/deploy.sh</argument></arguments>
</configuration>

(And, in general case, /bin/sh is more portable, bash could be in many different places.)

Oleg Muravskiy
  • 705
  • 5
  • 8
4

You need to set the appropriate permissions to the script and put the permission also into your version control either git (.gitattributes) or in Subversion (svn:executable property).

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks. Is [this](http://stackoverflow.com/a/10783833/6533075) the correct way to do it for Git? – Schütze Jul 15 '16 at 13:32
  • This [link](http://blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.html) helped me to change the linux permissions : `> git update-index --chmod=+x script.sh` – Ghurdyl Jun 04 '18 at 07:27