Lint: abortOnError из командной строки - PullRequest
0 голосов
/ 21 мая 2019

Есть ли способ установить abortOnError из командной строки? Без изменения build.gradle:

lintOptions {
  abortOnError false
}

Lint имеет параметр --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'.

Lint doc:

--exitcode: Set the exit code to 1 if errors are found.

1 Ответ

0 голосов
/ 21 мая 2019

Кажется, нет способа сделать это.

Смешной обходной путь - переписать 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"
...