skuzzle/restrict-imports-enforcer-rule

Feature request: exclude generate-sources and/or generate-test-sources

Closed this issue · 4 comments

A maven plugin or annotation processor may generate code using imports that we normally ban, and it is not possible to control the code generation.

It would be nice we can ignore a whole directory such as target/generated-sources. I understand this can be done on package level, but sometimes we have generated code and human written code in the same package but different directories.

I took a look at the code and I think if we could do something around the following lines to filter out excluded folders, it might work.

final Collection<Path> srcDirectories = this.includeCompileCode
                ? listSourceRoots(mavenProject.getCompileSourceRoots())
                : Collections.emptyList();
final Collection<Path> testDirectories = this.includeTestCode
                ? listSourceRoots(mavenProject.getTestCompileSourceRoots())
                : Collections.emptyList();

That's actually a very valid request and as you already found out it should be pretty straight forward to implement.
I think that target/generated-sources is a pretty standard location for generated files so it might be a sensible default exclusion. Making the exclusions configurable would be the icing on the cake.

I'll happily accept a pull request with the feature, but I'd also take care of it myself if I find the time.

Cool, thanks for confirming the validity of it. I will give it a try.

Will be released as 1.3.0