Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在build.gradle中进行行计数_Gradle - Fatal编程技术网

在build.gradle中进行行计数

在build.gradle中进行行计数,gradle,Gradle,我的构建文件夹中有一个文件,其中包含有关依赖关系问题的信息 我想计算依赖问题报告(文件)中的行数 我有以下伪代码: dependencyCheckAnalyze.doLast { // check if there are bad dependencies if ('build/reports/dependency-check-report.csv'.linecount > 1) { // line 1 is the title (ie. all depe

我的构建文件夹中有一个文件,其中包含有关依赖关系问题的信息

我想计算依赖问题报告(文件)中的行数

我有以下伪代码:

dependencyCheckAnalyze.doLast {
    // check if there are bad dependencies
    if ('build/reports/dependency-check-report.csv'.linecount > 1) { 
        // line 1 is the title (ie. all dependency problems comes on next lines)
        // do stuff regarding dependency issues
    }
}

使用Groovy的一些基本功能,您可以轻松计算字符串中的行数:

task countLines{
    doLast{
        println "Number of lines: " + file('build.gradle').text.readLines().size()

    }
}

我认为您需要在while循环中调用
java.io.BufferedReader.readLine()
,直到它返回null。这将不必要地将整个文件读入内存。可能不是问题,但肯定不是最佳实践在这种情况下:“一个包含依赖性问题信息的文件”,将不会有内存/性能问题,我假设项目中没有足够的依赖性问题来对内存造成一些损害;)但我同意你的看法,对于其他类型的文件,流/缓冲将是一种更好的方法。