ktlint-maven-plugin
ktlint-maven-plugin copied to clipboard
Exclude target directory
I'm using apt/kapt to auto generate some source files. I want to exclude these when running ktlint check This is a maven project.
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>1.4.2</version>
<configuration>
<sourcesExcludes>
<sourcesExclude>target/generated-sources/kapt/compile/*</sourcesExclude>
<sourcesExclude>**/generated-sources/kapt/**</sourcesExclude>
<sourcesExclude>target/generated-sources/kapt/compile/**</sourcesExclude>
<exclude>target/generated-sources/kapt/compile/*</exclude>
<exclude>target/generated-sources/kapt/compile/**</exclude>
<exclude>target/generated-sources/kapt/compile</exclude>
<exclude>**/generated-sources/kapt/**</exclude>
</sourcesExcludes>
</configuration>
<executions>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
I have tried sourcesExcludes with many different values as shown above, But it is still reporting errors in these files.
How do i exclude directories?
After several hours i think i'm starting to see the problem. I am able to exclude/include package folders, But the plugin does not seem to be aware of whether they exist in src or target. So if i exclude a folder path then this path will be excluded from both src and target.
I have the same issue. For me just excluding a specific package would work.
Of course, a better solution would be to just include the sources in the /src/main/kotlin and /src/test/kotlin folder
I have the same problem: I'm trying to exclude some generated sources in the target/generated-sources directory, but they're still checked.
I don't like to use package names in the excludes if it can be avoided.
Setting configuration sourceRoots to ${project.build.sourceDirectory} works for me (avoids check goal from throwing errors on Kapt files).
Example:
<configuration>
<sourceRoots>${project.build.sourceDirectory}</sourceRoots>
</configuration>
Setting configuration
sourceRootsto${project.build.sourceDirectory}works for me (avoidscheckgoal from throwing errors on Kapt files).Example:
<configuration> <sourceRoots>${project.build.sourceDirectory}</sourceRoots> </configuration>
Thanks, this is something to try!
<configuration> <sourceRoots>${project.build.sourceDirectory}</sourceRoots> </configuration>
Thanks @jhult! This solves the problem. I noticed however this field is not supposed to be set, it doesn't even show in the plugin help and setting it gives warning during the build. I understood the issue with sourcesIncludes and sourcesExcludes is that they search inside the source roots. And it's clear sourceRoots by default contains all sources added to maven, including for example the ones added by plugins.
It'd be great to have an official way to exclude source roots based on their path or another mechanism to prevent generated sources to be checked.
I also couldn't get the this working with sourcesExcludes and like @lucasls was able to get it working with the sourceRoots but get:
[WARNING] Parameter 'sourceRoots' is read-only, must not be used in configuration