Skip to content
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

Exclude target directory #341

Open
IceBlizz6 opened this issue Jul 6, 2020 · 7 comments
Open

Exclude target directory #341

IceBlizz6 opened this issue Jul 6, 2020 · 7 comments

Comments

@IceBlizz6
Copy link

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
Copy link
Author

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.

@michael-wirth
Copy link

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

@tnleeuw
Copy link

tnleeuw commented Jan 11, 2021

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.

@jhult
Copy link
Contributor

jhult commented Mar 3, 2021

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>

@tnleeuw
Copy link

tnleeuw commented Mar 3, 2021

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!

@lucasls
Copy link

lucasls commented Aug 14, 2023

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

@jamesward
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants