Maven - Dependency on module for Checkstyle not working

Viewed 2196

Project Link: https://github.com/randomquestion/MultiModuleMavenCheckstyleSample

I have a very simple Maven project with multiple modules. I'm following this Maven guide to enable Checkstyle on it. So I created a common module named build-tools (as per guide) and added Checkstyle configuration in root pom file. However I'm running to a very weird issue.

When I create a new Maven project from scratch, mvn clean install seems to work just fine including Checkstyle. However as soon as I rename the checkstyle file and update pom.xml with new name, build starts failing with the error Could not find resource <new Checkstyle file name>. After that, I can never get it to build again. The problem it seems is that the dependency on build-tools module in root pom is not working.

├── build-tools
│   ├── build-tools\ (1).iml
│   ├── pom.xml
│   ├── src
│       └── main
│           └── resources
│               └── default-checkstyle.xml
├── pom.xml

Root pom.xml:

<modules>
  <module>build-tools</module>
</modules>

<properties>
  <checkstyle.config.location>default-checkstyle.xml</checkstyle.config.location>
</properties>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>2.17</version>
      <dependencies>
        <dependency>
          <groupId>com.mycompany.app</groupId>
          <artifactId>build-tools</artifactId>
          <version>1.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
      <executions>
        <execution>
          <id>validate</id>
          <phase>validate</phase>
          <configuration>
            <configLocation>default-checkstyle.xml</configLocation>
            <encoding>UTF-8</encoding>
            <consoleOutput>true</consoleOutput>
            <failOnViolation>true</failOnViolation>
          </configuration>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

build-tools pom.xml

<parent>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
</parent>

<groupId>com.mycompany.app</groupId>
<artifactId>build-tools</artifactId>
<version>1.0-SNAPSHOT</version>
<name>build-tools</name>

Error:

INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] my-app
[INFO] build-tools
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-app ---
[INFO] Deleting /Users/../workspace/my-app/target
[INFO]
[INFO] --- maven-checkstyle-plugin:2.17:check (validate) @ my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my-app ............................................. FAILURE [  1.170 s]
[INFO] build-tools ........................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.291 s
[INFO] Finished at: 2017-09-13T22:25:26-07:00
[INFO] Final Memory: 12M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project my-app: Failed during checkstyle execution: Unable to find configuration file at location: default-checkstyle.xml: Could not find resource 'default-checkstyle.xml'. -> [Help 1]

Any suggestions on what might be going wrong? Why is mvn install not building build-tools module first?

2 Answers
Related