我需要从蚂蚁那里打电话给sbt。我和#34; exec"任务如下:
<target name="publish-jar">
<exec executable="sbt.bat" failonerror="true">
<arg value="publish"/>
</exec>
</target>
我需要蚂蚁任务,以及#34;失败&#34;如果sbt任务失败,这就是使用failonerror="true"
的原因。但是,这不起作用。当sbt任务失败时,ant不会报告失败的构建。
这看起来像这里讨论的问题:Ant exec resultproperty is not working。建议的解决方法是删除&#34; / B&#34;来自sbt.bat
。换句话说,改变:
exit /B %ERROR_CODE%
到
exit %ERROR_CODE%
然而,正如一位评论者所说:
这样做的缺点是,如果直接运行批处理文件进行测试,它将终止你的shell。您可以在批处理文件中使用if和arg来选择\ b,当ant调用它时,正常退出时不选择。
问题:是否有修复,当发生故障时:(1)不终止调用者的shell和(2)将退出代码传播给ant?
这是运行我的ant任务的输出。实际错误在这里并不重要(我故意没有配置存储库来发布,强制错误):
C:\dev\la\sdf3\modules\test>ant publish-jar
Buildfile: C:\dev\la\sdf3\modules\test\build.xml
publish-jar:
[exec] [info] Loading global plugins from C:\Users\jn\.sbt\0.13\plugins
[exec] [info] Set current project to test (in build file:/C:/dev/la/sdf3/modules/test/)
[exec] :: loading settings :: file = C:\dev\la\sdf3\modules\ivysettings.xml
[exec] [info] :: delivering :: com.jn#test;SNAPSHOT ::
SNAPSHOT :: integration :: Fri Mar 14 08:45:58 HST 2014
[exec] [info] delivering ivy file to C:\dev\la\sdf3\modules\com.jn\target\scala-2.10\ivy-SNAPSHOT.xml
[exec] java.lang.RuntimeException: Repository for publishing is not specified.
[exec] at scala.sys.package$.error(package.scala:27)
[exec] at sbt.Classpaths$$anonfun$getPublishTo$1.apply(Defaults.scala:1203)
[exec] at sbt.Classpaths$$anonfun$getPublishTo$1.apply(Defaults.scala:1203)
[exec] at scala.Option.getOrElse(Option.scala:120)
[exec] at sbt.Classpaths$.getPublishTo(Defaults.scala:1203)
[exec] at sbt.Classpaths$$anonfun$57.apply(Defaults.scala:1037)
[exec] at sbt.Classpaths$$anonfun$57.apply(Defaults.scala:1037)
[exec] at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[exec] at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
[exec] at sbt.std.Transform$$anon$4.work(System.scala:64)
[exec] at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
[exec] at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
[exec] at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
[exec] at sbt.Execute.work(Execute.scala:244)
[exec] at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
[exec] at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
[exec] at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
[exec] at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
[exec] at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[exec] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[exec] at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[exec] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[exec] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[exec] at java.lang.Thread.run(Thread.java:744)
[exec] [error] (*:publishConfiguration) Repository for publishing is not specified.
[exec] [error] Total time: 0 s, completed Mar 14, 2014 8:45:59 AM
BUILD SUCCESSFUL
Total time: 4 seconds
答案 0 :(得分:2)
我刚做了一个简单的批次:
@echo off
echo [batch]
exit /b 2
从上面你的ant脚本,exec返回我的批处理中的错误代码。一切都很好。
exec returned: 2
对此进行了测试:
Apache Ant(TM) version 1.9.3 compiled on December 23 2013
上的Windows 7 64-bit
您应该粘贴批处理文件以及运行ant时获得的实际结果。您正在使用的Ant版本有问题,或者(很可能)批处理文件有问题。
执行以下操作
sbt.bat publish
echo %ERRORLEVEL%
之后立即注意结果如果您收到0
,那么您的批次就成了问题。
编辑: 或者,有article here描述了使用macrodef
的变通方法