1

I have a maven project in which I execute a windows .bat file using maven exec plugin. The problem is that, even if the bat execution fails (i.e. exit code is -1) the build of the project is SUCCESS.

Here is my defined plugin:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <version>1.4.0</version>
   <executions>
       <execution>
           <phase>compile</phase>
           <goals>
               <goal>exec</goal>
           </goals>
           <configuration>
               <executable>run.bat</executable>
           </configuration>
       </execution>
   </executions>
</plugin>

Please note that the same behave as expected if I execute it on Unix (i.e. execute .sh file and build fails).

trydis
  • 3,905
  • 1
  • 26
  • 31
vadim
  • 993
  • 13
  • 29

1 Answers1

1

See noahlz answer to the question Launching a windows batch script using Maven exec plugin ...:

Windows Batch Files are not executable. They are scripts that are run by the cmd executable.

... the short version is: this isn't a problem with "Maven," it's a problem with the platform-dependent nature of executing an exec() command.

If a command in your run.bat sets %ERRORLEVEL% this is set in the executing CMD but not passed to CMD's caller, i.e. the Maven Exec plugin. Exiting your run.bat with EXIT %ERRORLEVEL% explicitely should do the trick.

Community
  • 1
  • 1
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Gerold Broser, thanks for pointing to noahlz answer (actually I already found it) Unfortunatelly, exiting with %ERRORLEVEL% doesn't help. So I followed noahlz' advise to deconstruct the .bat script into its actual commands and launch it directly from the exec plugin. – vadim Sep 07 '15 at 10:57