ktlint-maven-plugin icon indicating copy to clipboard operation
ktlint-maven-plugin copied to clipboard

Exclude target directory

Open IceBlizz6 opened this issue 5 years ago • 7 comments

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?

IceBlizz6 avatar Jul 06 '20 23:07 IceBlizz6

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.

IceBlizz6 avatar Jul 07 '20 13:07 IceBlizz6

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

michael-wirth avatar Aug 07 '20 11:08 michael-wirth

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.

tnleeuw avatar Jan 11 '21 14:01 tnleeuw

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>

jhult avatar Mar 03 '21 05:03 jhult

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>

Thanks, this is something to try!

tnleeuw avatar Mar 03 '21 09:03 tnleeuw

<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.

lucasls avatar Aug 14 '23 16:08 lucasls

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

jamesward avatar Aug 21 '23 15:08 jamesward