eygraber
10/27/2021, 6:38 PMdetektMain
on my project.
One of my library modules generates code in build/generated/myapp/kotlin
which is added as a source set to main like so:
extensions.getByType<LibraryExtension>().sourceSets {
named("main") {
java {
srcDir(layout.buildDirectory.file("generated/myapp/kotlin"))
}
}
}
However, I don't want detekt to look at generated files. How can I prevent that?chao
10/27/2021, 6:39 PMchao
10/27/2021, 6:40 PMbuild/generated
is an anti-pattern for Gradle. Usually we generate a specific source set outside the build
directoryeygraber
10/27/2021, 6:49 PMchao
10/27/2021, 7:40 PMfileTree
and Detekt task itself is a SourceTask
, so we should be able to configure the specific task’s source
to exclude some directory, or even invoke SourceTask.exclude
. I have not tried it yet but I have high confidence that this would workeygraber
10/27/2021, 9:00 PMdetekt {
source.asFileTree.matching {
exclude { "build" in it.path }
}
}
But it's still including those fileschao
10/27/2021, 11:13 PMDetektTask
?chao
10/27/2021, 11:13 PMdetekt {}
is to configure the detekt extensioneygraber
10/28/2021, 4:34 AMephemient
10/28/2021, 6:36 AMdetektMain
): https://github.com/detekt/detekt/issues/4127Gama11
10/28/2021, 12:09 PMsrc/main
and then .gitignoring that) when migrating our project from maven to gradle because it seemed easier in some regards, but I thought it's a hack I should clean up eventually... :)eygraber
10/28/2021, 1:21 PMchao
10/28/2021, 3:42 PMbuild/
and adding folders under build/
into source set.chao
10/28/2021, 3:50 PMbuild
are cleanable, and as plugin authors, we sometimes delete files under build
folder to prevent cacheability issues (Sync
as a standard task in Gradle, works in a similar fashion https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Sync.html)
This also fits semantic meanings of src
and build
Gama11
10/28/2021, 4:28 PMchao
10/28/2021, 5:00 PMchao
10/28/2021, 5:04 PMeygraber
10/28/2021, 6:57 PMephemient
10/28/2021, 9:06 PM.jar
and -sources.jar
and everything should just work