0

I want build to fail if 'checkstyle' detects any error. I referred to how to stop maven build using checkstyle and https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html. My pom.xml looks like this:

<build>
     <pluginManagement>
      <plugins>
       .....
       .....
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.11</version>
                <executions>
                    <execution>
                        <id>validate</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <configLocation>config/sun_checks.xml</configLocation>  
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>true</failsOnError>
                            <linkXRef>false</linkXRef>
                        </configuration>
                    </execution>
                </executions>
            </plugin>  
        </plugins>
      </pluginManagement>
</build>

Running checkstyle:check reports the errors in source. But running install succeeds. I have tried binding the plugin to validate, process-sources and other phases. But build succeeds all the time. Am I missing some configuration?

1 Answer 1

4

You shouldn't use pluginManagement in this case. pluginManagement is a way to control plugin configuration in a parent for all depending projects. If a child (or the project itself) wants to use it, it should add the plugin to the build/plugins:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <!-- no version required -->
    </plugin>
  </plugins>
</build>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! Moved the configuration out of pluginmanagement and it works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.