是否可以从命令行设置abortOnError
?无需更改build.gradle
:
lintOptions {
abortOnError false
}
棉绒具有--exitcode
参数,该参数显然可以正常工作,但是./gradlew lint
不接受任何参数。
错误:
FAILURE: Build failed with an exception.
* What went wrong:
Problem configuring task :app:lint from command line.
> Unknown command-line option '--exitcode'.
皮棉文档:
--exitcode: Set the exit code to 1 if errors are found.
答案 0 :(得分:0)
似乎没有办法做到。
荒谬的解决方法是覆盖build.gradle
并添加lintOptions { abortOnError false }
。工作脚本:
import os
import sys
def is_app_build_gradle(file_path):
gradle_file = open(file_path)
file_content = gradle_file.read()
if file_content.__contains__('android') and file_content.__contains__('signingConfigs'):
return True
else:
return False
def find_build_gradle(project_path):
name = 'build.gradle'
walk = os.walk(project_path)
for root, dirs, files in walk:
if name in files:
file_path = os.path.join(root, name)
if is_app_build_gradle(file_path):
return file_path
raise Exception('Not found app build.gradle in ' + project_path)
def write_abort_on_error_false(file_path):
gradle_file = open(file_path)
file_content = gradle_file.read()
if file_content.__contains__('abortOnError false'):
print 'already false'
return
file_content = file_content.replace('android {', 'android { lintOptions {abortOnError false}')
to_write = open(file_path, "w")
to_write.write(file_content)
to_write.close()
if __name__ == '__main__':
if len(sys.argv) == 1:
raise Exception('Android project path is not defined')
project_path = sys.argv[1]
gradle_file_path = find_build_gradle(project_path)
write_abort_on_error_false(gradle_file_path)
print 'success'
用法
python add_abort_on_error.py "path/to/android/project"
答案 1 :(得分:0)
以这种方式修改lintOptions
:
lintOptions {
abortOnError project.getProperties().getOrDefault("abortOnError", false)
}
然后,您将能够通过带有-PabortOnError=true
参数的命令行运行lint:
./gradlew lint -PabortOnError=true