Situation
I have a project with a CheckStyle setup which uses the SuppressionFilter to set the checkstyle_suppressions.xml file as ignore file.
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/checkstyle_suppressions.xml"/>
<property name="optional" value="false"/>
</module>
The checkstyle.xml file containing this SuppressionFilter is referenced to from the projects pom.xml file:
<!-- Checkstyle plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>test</phase>
<configuration>
<sourceDirectories>${project.compileSourceRoots}</sourceDirectories>
<testSourceDirectories>${project.testCompileSourceRoots}</testSourceDirectories>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.9</version>
</dependency>
</dependencies>
</plugin>
Problem
When performing a CheckStyle check using Java Eclipse, everything functions as expected. When building with maven, however, the build fails due to the ${config_loc} property not being set. Original error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (checkstyle) on project MyProject: Failed during checkstyle execution: Failed during checkstyle configuration: unable to parse configuration stream: Property ${config_loc} has not been set -> [Help 1]
When changing ${config_loc}/checkstyle_suppressions.xml to checkstyle_suppressions.xml in the configuration above, maven builds the application as expected, but Java Eclipse's CheckStyle plugin is not able to parse the file anymore, printing the following exception to the log:
!ENTRY net.sf.eclipsecs.core 4 0 2018-06-07 05:40:02.460 !MESSAGE Checkstyle-Plugin: cannot initialize module SuppressionFilter - Unable to find: checkstyle_suppressions.xml !STACK 0 com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module SuppressionFilter - Unable to find: checkstyle_suppressions.xml at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:460) at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:198) at net.sf.eclipsecs.core.builder.CheckerFactory.createCheckerInternal(CheckerFactory.java:299) at net.sf.eclipsecs.core.builder.CheckerFactory.createChecker(CheckerFactory.java:133) at net.sf.eclipsecs.core.builder.Auditor.runAudit(Auditor.java:141) at net.sf.eclipsecs.core.builder.CheckstyleBuilder.handleBuildSelection(CheckstyleBuilder.java:306) at net.sf.eclipsecs.core.builder.CheckstyleBuilder.build(CheckstyleBuilder.java:172) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56) Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to find: checkstyle_suppressions.xml at com.puppycrawl.tools.checkstyle.utils.CommonUtils.getUriByFilename(CommonUtils.java:510) at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:202) at com.puppycrawl.tools.checkstyle.filters.SuppressionFilter.finishLocalSetup(SuppressionFilter.java:100) at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:194) at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:455) ... 18 more
Solve attempts
I have tried to set this ${config_loc} variable in the maven pom in multiple places, but without success.
Question
How can I set up my CheckStyle configuration so that it works for both Maven and Java Eclipse? I am looking for a distributable solution, meaning that other developers which clone or fork this project will not face this problem.