Skip to content

DetektAll with baseline fails with error #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adrianczuczka opened this issue Nov 18, 2019 · 9 comments · Fixed by #2140
Closed

DetektAll with baseline fails with error #2100

adrianczuczka opened this issue Nov 18, 2019 · 9 comments · Fixed by #2140
Labels
Milestone

Comments

@adrianczuczka
Copy link

adrianczuczka commented Nov 18, 2019

I have a multi-module project and I want to create one baseline file for the entire project instead of one per module, so I'm trying to replicate the detektAll task that is created in this project's build.gradle.kts file. However, I have had to translate this task into Groovy, and it looks like this:

task detektAll(type: io.gitlab.arturbosch.detekt.Detekt) {
    description = 'Runs over whole code base without the starting overhead for each module.'
    config = files("$rootDir/detekt-config.yml")
    parallel = true
    input = files(projectDir)
    include '**/*.kt'
    include '**/*.kts'
    exclude '**/resources/**'
    exclude '**/build/**'
    baseline = file("$rootDir/config/detekt/baseline.xml")
    reports {
        xml {
            enabled = true
        }
        html {
            enabled = true
        }
        txt {
            enabled = true
        }
    }
}

However, running this fails with the error

A problem was found with the configuration of task ':detektAll'.
File (my root directory)/config/detekt/baseline.xml does not exist.

Is there a fix for this?

@schalkms
Copy link
Member

Did you execute the detektBaseline task before, which generates the baseline.xml file?
./gradlew detektBaseline

@adrianczuczka
Copy link
Author

adrianczuczka commented Nov 19, 2019

When I run detektBaseline, it generates a baseline file for every module, which is what I want to avoid.

@adrianczuczka
Copy link
Author

I have run detektBaseline again but this time I set my baseline in the detekt block to the same file:

detekt {
    config = files("$rootDir/detekt-config.yml")
    filters = ".*build.*,.*/resources/.*,.*/tmp/.*"
    //Optional baseline, uncomment & run gradle command detektBaseline to exclude existing issues
    baseline = file("$rootDir/baseline.xml")
}

This does generate only one baseline, but the file itself is basically empty even after the task has finished:

<?xml version="1.0" ?>
<SmellBaseline>
  <Blacklist></Blacklist>
  <Whitelist>
    <ID>ParameterListWrapping:</ID>
  </Whitelist>
</SmellBaseline>

That's the entire file. Additionally, running the detektAll task does not update this baseline at all.

@adrianczuczka
Copy link
Author

It might be that if the baseline is the same the whole time, it gets overwritten every time a new module is scanned?

@schalkms
Copy link
Member

I also suspect that.
@arturbosch can you confirm that?

@arturbosch
Copy link
Member

arturbosch commented Nov 27, 2019

Sorry for the late response @adrianczuczka , you can create a custome baseline task which generates it for the whole project as well:

task baseline(type: io.gitlab.arturbosch.detekt.DetektCreateBaselineTask) {
    description = "Overrides current baseline."

    input = files(rootProject.projectDir)
    config = files("$rootDir/detekt/config.yml")
    baseline = file(new File(rootProject.projectDir, "/detekt/baseline.xml"))
    failFast = true
    parallel = true
    include '**/*.kt'
    include '**/*.kts'
    exclude '**/test/resources/**'
    exclude '**/afk-*/build/**'
}

For the modules you already have overridden the baseline :)

@schalkms
Copy link
Member

schalkms commented Nov 27, 2019

That's cool!
We might want to add this to the documentation as well.
https://arturbosch.github.io/detekt/baseline.html

@adrianczuczka
Copy link
Author

adrianczuczka commented Nov 28, 2019

Thank you so much for the Gradle task! I had to change a few things to make the task work:
baseline = file(new File(rootProject.projectDir, "/detekt/baseline.xml"))
gave me an error saying cannot resolve symbol File and had to be changed to
baseline = file(rootProject.projectDir, "/detekt/baseline.xml").

Just checked again and it seems the error in baseline = file(new File(rootProject.projectDir, "/detekt/baseline.xml")) is reported by the IDE but does not actually cause a build error, which is weird.

Also, failFast = true causes the task to fail, and it seems like any DetektCreateBaselineTask does not correctly handle failures. I had to comment out the maxIssues property in my config file, but I think adding ignoreFailures = true instead works as well.

On the surface, it seems that the task works. However, running detekt with this baseline, it still fails with a lot of uncaught issues.

@adrianczuczka
Copy link
Author

adrianczuczka commented Nov 28, 2019

I think it works now, and what I had to do is move the task into a subprojects block.

@arturbosch arturbosch added this to the 1.3.1 milestone Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants