Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[MCHECKSTYLE-299] build type check goal ignored source options when using phases "test site"

Open
#232 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
build-system

Research direction

Reproduce the configuration with Maven using the commands listed, especially mvn test site, and inspect the effective configuration with mvn -X. Compare the sourceDirectories handling in the check goal against the deprecated sourceDirectory behavior; done means mvn test site checks only the configured source trees rather than all source trees.

Written by the indexing model from the issue text.

Description

enhancement priority:major

Johannes Wienke opened MCHECKSTYLE-299 and commented

I have a project where we enforce a zero-warnings policy. For this purpose we have included a call to checkstyle:check in the build phase using the following configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.15</version>
    <configuration>
        <configLocation>${project.basedir}/codecheck/checkstyle.xml</configLocation>
        <propertyExpansion>config_loc=${project.basedir}/codecheck</propertyExpansion>
        <includeTestSourceDirectory>true</includeTestSourceDirectory>
        <consoleOutput>true</consoleOutput>
        <violationSeverity>warning</violationSeverity>
        <failOnViolation>true</failOnViolation>
        <sourceDirectory>${project.basedir}/src</sourceDirectory>
    </configuration>
    <executions>
        <execution>
            <id>checkstyle-validate</id>
            <phase>validate</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Additionally, checkstyle is set up as a reporting goal in the reporting section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.15</version>
    <configuration>
        <configLocation>${project.basedir}/codecheck/checkstyle.xml</configLocation>
        <propertyExpansion>config_loc=${project.basedir}/codecheck</propertyExpansion>
        <includeTestSourceDirectory>true</includeTestSourceDirectory>
        <sourceDirectory>${project.basedir}/src</sourceDirectory>
    </configuration>
</plugin>

The project contains multiple source trees and some contain generated code. Therefore it is necessary to restrict checkstyle to only one of these trees where the manually maintained code lives. Otherwise, the build would fail due to warnings being detected in generated code.

This shown configuration works well when calling maven all of the following ways:

mvn compile
mvn test
mvn site
mvn test site

However, when changing the deprecated sourceDirectory elements to the list syntax with sourceDirectories, the last call mvn test site starts to fail and ignores the specified source directories. All previous other calls still work as expected.

When looking at the effective configuration using mvn -X I could see, that in the last call version with "test site", the sourceDirectories list of the check goal is again the complete list of source trees instead of the specified one.

Since we are also using some plugins to include the generated code etc., a reference to the complete POM might be helpful for debugging:
https://code.cor-lab.org/projects/rsb/repository/rsb-java/revisions/master/entry/pom.xml


Affects: 2.15

Dominant language
Java
Stars
97
Forks
68
Avg merge
2d 14h
Merged PRs (30d)
8

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/maven-checkstyle-plugin

All issues in apache/maven-checkstyle-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.