仅当 运行 没有检查任务时检测任务才会失败
Detekt task fails only if ran without check task
我正在将 detekt 从 1.0.0.RC7-2 迁移到 1.0.1 并改为使用新的插件语法。我设法使它工作,但只有在执行完整检查任务时才可以。
如果只执行 detekt 任务,则会显示错误。
检测任务失败并出现以下错误:
Task :detekt FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':detekt'.
Could not resolve all files for configuration ':detekt'.
Cannot resolve external dependency io.gitlab.arturbosch.detekt:detekt-cli:1.0.1 because no repositories are defined.
Required by:
project :
detekt.gradle
apply plugin: 'io.gitlab.arturbosch.detekt'
detekt {
config = files("$rootDir/detekt/detekt-ruleset.yml")
filters = ".*build.*,.*/resources/.*,.*/tmp/.*"
input = files("src/main/java", "src/test/java")
reports {
html.enabled = true
xml.enabled = false
txt.enabled = false
}
}
build.gradle(项目):
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1"
}
}
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.1"
}
build.gradle(模块):
repositories {
jcenter()
google()
}
apply from: "$rootDir/detekt/detekt.gradle"
根据 detekt repo 上的这个 issue 文件,你必须在根项目上配置它,而不是在应用程序模块上。
我通过为 Detekt 创建任务而不是使用插件设法使其工作:
detekt.gradle
configurations {
detekt
}
dependencies {
detekt "io.gitlab.arturbosch.detekt:detekt-cli:1.0.1"
}
task detekt(type: JavaExec) {
main = "io.gitlab.arturbosch.detekt.cli.Main"
classpath = configurations.detekt
def input = "$rootDir"
def config = "$rootDir/detekt/detekt-ruleset.yml"
def exclude = ".*/resources/.*,.*/build/.*"
def report = "html:${project.buildDir}/reports/detekt.html"
def params = ['-i', input, '-c', config, '-ex', exclude, '-r', report]
args(params)
}
check.dependsOn detekt
build.gradle(项目)
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1"
}
}
我正在将 detekt 从 1.0.0.RC7-2 迁移到 1.0.1 并改为使用新的插件语法。我设法使它工作,但只有在执行完整检查任务时才可以。
如果只执行 detekt 任务,则会显示错误。
检测任务失败并出现以下错误:
Task :detekt FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':detekt'.
Could not resolve all files for configuration ':detekt'.
Cannot resolve external dependency io.gitlab.arturbosch.detekt:detekt-cli:1.0.1 because no repositories are defined.
Required by:
project :
detekt.gradle
apply plugin: 'io.gitlab.arturbosch.detekt'
detekt {
config = files("$rootDir/detekt/detekt-ruleset.yml")
filters = ".*build.*,.*/resources/.*,.*/tmp/.*"
input = files("src/main/java", "src/test/java")
reports {
html.enabled = true
xml.enabled = false
txt.enabled = false
}
}
build.gradle(项目):
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1"
}
}
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.1"
}
build.gradle(模块):
repositories {
jcenter()
google()
}
apply from: "$rootDir/detekt/detekt.gradle"
根据 detekt repo 上的这个 issue 文件,你必须在根项目上配置它,而不是在应用程序模块上。
我通过为 Detekt 创建任务而不是使用插件设法使其工作:
detekt.gradle
configurations {
detekt
}
dependencies {
detekt "io.gitlab.arturbosch.detekt:detekt-cli:1.0.1"
}
task detekt(type: JavaExec) {
main = "io.gitlab.arturbosch.detekt.cli.Main"
classpath = configurations.detekt
def input = "$rootDir"
def config = "$rootDir/detekt/detekt-ruleset.yml"
def exclude = ".*/resources/.*,.*/build/.*"
def report = "html:${project.buildDir}/reports/detekt.html"
def params = ['-i', input, '-c', config, '-ex', exclude, '-r', report]
args(params)
}
check.dependsOn detekt
build.gradle(项目)
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1"
}
}