English 中文(简体)
停止格拉斯建筑的建议途径
原标题:Recommended way to stop a Gradle build

How can I stop a Gradle build after detecting a problem? I can use an assert, throw an exception, do a System.exit (bad idea), or use a dedicated function in Gradle (but I could not find one). What is the best way for Gradle (and why?).

最佳回答

http://docs.gradle.org/Depts/DGACM/index_chinese.htm

如果你想要停止目前的任务或行动,并着手下一步工作,你还可以投下rel=“noreferer”>StopActionException

问题回答

如果你想要停止建造,就会扔下:

throw new GradleException( error occurred )

或为上述例外情况下下下级。 某些次类例外实际上只失败了目前的任务,而是继续建造。

目前没有专门的方法,尽管已经讨论增加一个方法。

停止“格拉斯”建筑的建议方法是放弃一个例外。 由于格罗瓦尼没有检查例外情况,加格拉因违约不印刷例外类型,因此,它并不认为哪一个例外被推翻。 在打造文字时,经常使用“格罗维”的说法(视具体情况和受众而定)。 重要的是提供明确的信息。 添加原因(如果有的话)有助于分解(-stacktrace)。

谷物为阻止目前的任务/任务行动,但继续建造提供了专门的例外情况类型:<条码>标准>。

Throwing a simple GradleException works in stopping the build script. This works great for checking required environment setup.

GradleException( your message, why the script is stopped. )

例:

if(null == System.getenv()[ GRADLE_USER_HOME ]) {
    throw new GradleException( Required GRADLE_USER_HOME environment variable not set. )
}

如果你不希望以后能够赶上例外情况,另一种选择是把ant子 fail倒。 在我看来,这略为容易阅读,你可以不使用——————向用户发出冰电。

task (tarball, dependsOn: warAdmin) << {
    ant.fail( The sky is falling!! )
}

Gives you a message like:

* What went wrong:
Execution failed for task  :tarball .
> The sky is falling!!

或许,<>can追捕(如果丢掉了ant的 Build?)但如果达到目标,我将不使用ant。 我只想把标准梯度例外作为刺激物来看待渔获量有什么例外。

这里是一部成文法,试图推测格拉特哈瓦茨任务如何造成错误:

task myCommand(type:Exec) {

    ... normal task setup ....

    ignoreExitValue true
    standardOutput = new ByteArrayOutputStream()
    ext.output = { standardOutput.toString() }
    doLast {
        if (execResult.exitValue) {
            logger.error(output())
            throw new TaskExecutionException( it,
                new Exception( "Command  ${commandLine.join(   )}  failed; "
                              + "see task output for details." )
            )
        }
    }
}

指挥人员<代码>0 没有产出。 任何其他价值都将印刷标准产出并停止建筑。

NOTE:如果你的指挥写错误,你可能需要把错误记录列入。





相关问题
Elegant way building url request with parameters

There must me a more elegant way to build a URL with parameters in .NET then for example Response.Write("<a href=HeadOfMarketView.aspx"+Session["HOM"] != null ? Session["HOM"]+">Head of Market&...

buildforge problem

when i tried to run the job i am getting the error saying that No server could be found matching all conditions please any one help me on this

您能否防止MSBuild.exe经营活动?

我用文字建造一些项目,偶尔利用习俗制造事件,给建筑系统造成了很大困难。 如果有可能,我想援引MSBuild.exe。

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Keyboard shortcut to build only startup project?

I ve tried to find a keyboard shortcut to build only the startup project In VS2008. I only found a configurable shortcut to build the project which is currently viewed, which isn t as good. Any ...

Dependency bundle (jar-files/sources/API docs) in Eclipse

I m developing various in-house extensions for JIRA, the issue tracker we use. So far I worked with Netbeans and everything worked like a charm. However, now I need to switch to Eclipse and I m ...

How to link to a static library in C?

I use code::blocks to compile my static library. The output result is a libstatic.a file. Now, how do I link to my library to use functions that were compiled? (I tried to use #include "libstatic.a"...

热门标签