0

gradle bulid に checkstyle チェックを追加しました。構成は次のとおりです。

checkstyle {
    configFile = new File("${project.projectDir}/config/checkstyle/sun_checks.xml")
    showViolations = false
}

checkstyleMain {
    doLast{
        println("checkstyle main")
        project.ext.checkType = "main"
        tasks.checkstyleReport.execute()
    }
}


checkstyleTest {
    doLast{
        println("checkstyle test")
        project.ext.checkType = "test"
        tasks.checkstyleReport.execute()
    }
}

task checkstyleReport{
    checkstyleReport.outputs.upToDateWhen { false }
}

checkstyleReport << {
    logger.info("Producing checkstyle html report")
    final source = "${project.projectDir}/build/reports/checkstyle/${project.checkType}.xml"
    final xsl = "${project.projectDir}/config/checkstyle/checkstyle-simple.xsl"
    final output = "$buildDir/reports/checkstyle/${project.checkType}.html"
    println(source)
    println(xsl)
    println(output)
    ant.xslt(in: source,
             style: xsl,
             out: output
    )
}

私が呼び出すとき:

gradle --daemon clean checkstyleMain checktyleTest

出力は次のとおりです。

...
:clean
:compileJava
:processResources
:classes
:checkstyleMain
checkstyle main
/<root_path_here>/build/reports/checkstyle/main.xml
/<root_path_here>/config/checkstyle/checkstyle-simple.xsl
/<root_path_here>/build/reports/checkstyle/main.html
:compileTestJava
:processTestResources
:testClasses
:checkstyleTest
checkstyle test

ご覧のとおり、checkstyleReport タスクは 2 回呼び出されますが、出力は 1 回しか生成されません。私も試してみoutputs.upToDateWhen { false }ましたが、うまくいきません。

よろしくお願いします。

4

1 に答える 1

2

Gradle タスクは最大 1 回実行されます。また、タスクを明示的に呼び出すことはサポートされておらず、あらゆる種類の問題が発生します。正しいアプローチは、Checkstyle タスクごとにレポート タスクを宣言し (たとえば、タスク構成ルールを使用して)、その Checkstyle タスクに依存させる (または を使用するmustRunAfter) ことです。

于 2013-06-30T09:35:23.547 に答える