Domanda

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?

È stato utile?

Soluzione

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top