maven checkstyle未在目标中激发

hm2xizp9  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(363)

不知怎么的 checkstyle 目标不是我设定要执行的任务。
这是我的 POM :

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  ...
  <version>1.0-SNAPSHOT</version>

  <name>...</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.idk.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        ...
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <version>2.17</version>
          <configuration>
            <failsOnError>true</failsOnError>
            <configLocation>checkstyle.xml</configLocation>
            <consoleOutput>true</consoleOutput>
          </configuration>
          <executions>
            <execution>
              <id>build</id>
              <phase>build</phase>
              <goals>
                <goal>checkstyle</goal>
              </goals>
            </execution>
            <execution>
              <id>verify</id>
              <phase>verify</phase>
              <goals>
                <goal>checkstyle</goal>
              </goals>
            </execution>
            <execution>
              <id>package</id>
              <phase>package</phase>
              <goals>
                <goal>checkstyle</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

但如果我跑了 mvn verify 我看不到 checkstyle 已运行:

[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< ... >-----------------
[INFO] Building Icecream Shop Manager 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ ... ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory ...
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ ... ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to ...
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ ... ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory ...
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ ... ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to ...
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ ... ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running it.unipd.tos.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 s - in it.unipd.tos.AppTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ ... ---
[INFO] Building jar: ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.423 s
[INFO] Finished at: 2020-11-24T22:19:44+01:00
[INFO] ------------------------------------------------------------------------

我错过了什么?我不应该看到这样的东西吗:

[INFO] --- maven-checkstyle-plugin:2.17:checkstyle (default) @ ... ---
bakd9h0s

bakd9h0s1#

这个 <pluginManagement> 元素用于配置要继承的插件。您需要将checkstyle插件定义放在 <plugins> 元素,而不是在 <pluginManagement> 元素。

相关问题