How to make Gradle fail the build if a file dependency is not found?

Dav*_*vid 5 java gradle

I have a Gradle build that has some dependencies of the form

compile files('path/to/local/lib.jar')
Run Code Online (Sandbox Code Playgroud)

(the build is being migrated - eventually these will be replaced)

The build failed because one of these paths was incorrectly specified. But it failed due to a compile error - it looked like Gradle silently ignored the missing dependency.

Is there a simple option or switch that will force Gradle to fail the build if any dependency (particularly local file dependencies) cannot be resolved (eg., file missing)?

Edit: to clarify further:

If a dependency cannot be found in the configured repositories, Gradle will fail the build when attempting to resolve them, as expected.

BUT - if a dependency is defined as "compile files ....", and the file specified does not exist at build time, Gradle will IGNORE that error, and attempt compilation anyway. That seems spectacularly wrong-headed and inconsistent default behaviour.

我的问题是 - 是否有 Gradle 选项或开关或环境变量或系统属性可以设置以强制 Gradle 验证文件依赖项是否存在?(例如,以理智和理性的方式行事?)

Laz*_*ana 0

如果构建失败,您可以:

ant.fail('message why it failed')
Run Code Online (Sandbox Code Playgroud)

然后你可以设计一个条件,然后使构建失败并显示良好的消息;)

我建议创建一个任务,首先将文件引入项目,并有一个条件来检查文件是否可用等,如果不可用,则抛出 Gradle 异常并显示一条消息使构建失败,并在执行中首先执行该任务阶段。

我现在没有机会测试它,但它可能是这样的,如果有任何语法错误,请纠正我 - 但你应该明白这个想法。

def yourDep = $/\path\to\your\depdendency/$

task bringDeps << {

  if (yourDep.exists()){
    copy {
      from yourDep
      into $projectDir/depsOrSmthg
    }
  } else{
  ant.fail('message why it failed')
  }

}
Run Code Online (Sandbox Code Playgroud)