|
Please drop this request, this is not a maven issue. Windows batch files are quite different from processes, and are always executed in the context of a command prompt (cmd.exe). Ant worries about the return code of the cmd process, not the executed batch file's ERRORLEVEL. Seems harmless to add this in.... It may need to be: to avoid terminating cmd.exe if maven.bat was invoked from I have played around with this a bit on WinXP, and it seems like "exit /b %exit_code%" just sets the ERRORLEVEL and finishes the current batch script, whereas "exit %exit_code%" terminates cmd.exe with the errorlevel. "exit /b %ERRORLEVEL%" at the end of the batch file propably does nothing, as it seems to be intended to exit the batch somewhere in the middle. "exit %ERRORLEVEL%" at the end unfortunately terminates the process with the exit code (which is what you want when treating a batch file as a process, but not when you invoke it on the command line). Hm. I don't really understand why this is not a Maven issue. My company's build machine only invokes Ant, so I have a build.xml which does an Ant <exec> to run the Maven command (.sh or .bat depending on platform). Some time ago the builds for my project started always returning success, even when they have failed. I've been a staunch proponent of Maven (against much resistance I might add) at my company. This issue was highly visible... and not in a good way. As you might imagine, failed builds that no one knows about are pretty serious. All I know is that this used to work, the build machine has not been OS upgraded to XP or anything, and the EXIT %ERRORLEVEL% seems to fix the problem (although with the aforementioned nasty side-effects if you are running Maven in a CMD window yourself). Could someone at least take the time to explain why this isn't a Maven bug? Stuff like this may sound trivial but I can assure you that it is not. The fact of the matter is that most people use and are familiar with Ant, so making Maven seamlessly callable from Ant is a pretty big requirement. The Maven Ant task seems to be outdated (I spent quite a bit of time trying to get it to work but never solved forehead-related classloader issues). I have to agree with Bryan on this one. I have exactly the same requirement to call Maven from Ant and have likewise been unsuccessful with the MavenTask. Because of IDE integration with Ant and the need for Ant to do some file manipulation before Maven is invoked, it would be really great to have a solution for this. A batch file is executed via a cmd.exe command shell, either the Now, the problem is the shell's exit code. As far as I can tell, — build.xml java SomeMissingClass all: BUILD FAILED Unfortunately, as soon as you add other commands the — some.bat java SomeMissingClass goto end :end BUILD SUCCESSFUL Windows also sets a pseudo-environment variable ERRORLEVEL to — some.bat java SomeMissingClass goto end :end exit %ERRORLEVEL% BUILD FAILED But if the batch file is called by an existing shell (command line), One could explicitly spawn the shell, call the batch file, and end — build.xml Note the "/c" and the "call" before some.bat. THANK YOU for adding additional information. Last week the %ERRORLEVEL% patch to maven.bat did NOT work in a particular failure case (although it definitely works some of the time), so I'm still faced with builds that are bad but report success. I have not yet had time to investigate the specifics of what happened on this particular build, but the additional details are greatly appreciated. I'm a little confused here - does this need to be reopened or not? |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
This can be fixed, at least for Windows XP, by adding the following statement in the last line of maven.bat.
exit %ERRORLEVEL%
Thereby resolving the original issue.
...
and Settings/user/.maven/plugins/maven-test-plugin-1
1 error
2 warnings
BUILD FAILED
File...... file:/C:/Documents
.4/
Element... javac
Line...... 34
Column.... 46
Compile failed; see the compiler error output for details.
BUILD FAILED
C:\tmp\build.xml:160: Following error occured while exec
uting this line
C:\tmp\build.xml:103: exec returned: 70
Total time: 8 seconds