checkstyle-maven-plugin 3.2.2是否删除了'encoding'元素?

lztngnrs  于 2023-05-28  发布在  Maven
关注(0)|答案(1)|浏览(131)

当使用checkstyle-maven-plugin3.1.2时,我可以在这样的配置中定义一个编码元素:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>${maven-checkstyle-plugin.version}</version>
    <dependencies>
      <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>${checkstyle.version}</version>
      </dependency>
    </dependencies>
    <configuration>
      <configLocation>checkstyle.xml</configLocation>
      <encoding>UTF-8</encoding>
      <consoleOutput>true</consoleOutput>
      <failsOnError>true</failsOnError>
      <failOnViolation>true</failOnViolation>
      <violationSeverity>warning</violationSeverity>
      <linkXRef>false</linkXRef>
    </configuration>
    <executions>
      <execution>
        <id>validate</id>
        <phase>validate</phase>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

更新到版本3.2.2后,我得到提示“* 此处不允许使用元素编码 *”。我试着在文档中查找,但到目前为止还没有找到任何东西。我在哪里定义编码呢?
我尝试使用spring-boot-starter-parent版本2.7.11使用Maven 3.8.1和3.9.2,编译到Java版本11。
我删除了所有其他插件,依赖项......当使用maven-checkstyle.plugin版本3.2.2时,IntelliJ仍然抱怨该元素,而3.1.2版本可以正常工作。

<?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 
  https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

   <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.11</version>
    <relativePath/>
  </parent>

  <groupId>com.yyy.zzz</groupId>
  <artifactId>xxx</artifactId>
  <packaging>jar</packaging>

  <properties>
    <!-- Maven -->
    <java.version>11</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Checkstyle -->

    <!-- Plugins -->
    <maven-checkstyle-plugin.version>3.2.2</maven-checkstyle-plugin.version>
<!--    <maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>-->
<!--    <checkstyle.version>10.3.2</checkstyle.version>-->
    <checkstyle.version>10.11.0</checkstyle.version>

  </properties>

  <dependencies>
  </dependencies>

  <build>
    <finalName>xxx</finalName>

    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>

    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>${maven-checkstyle-plugin.version}</version>
      <dependencies>
        <dependency>
          <groupId>com.puppycrawl.tools</groupId>
          <artifactId>checkstyle</artifactId>
          <version>${checkstyle.version}</version>
        </dependency>
      </dependencies>
      <configuration>
        <configLocation>checkstyle.xml</configLocation>
        <encoding>${project.build.sourceEncoding}</encoding>
        <consoleOutput>true</consoleOutput>
        <failsOnError>true</failsOnError>
        <failOnViolation>true</failOnViolation>
        <violationSeverity>warning</violationSeverity>
        <linkXRef>false</linkXRef>
      </configuration>
      <executions>
        <execution>
          <id>validate</id>
          <phase>validate</phase>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

    </plugins>
  </build>

</project>

之后,我用这个POM在IntelliJ中创建了一个全新的Maven项目,仍然收到IntelliJ的警告:

<?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>

  <groupId>groupId</groupId>
  <artifactId>demo</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
      <maven.compiler.source>11</maven.compiler.source>
      <maven.compiler.target>11</maven.compiler.target>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- Checkstyle -->

    <!-- Plugins -->
    <maven-checkstyle-plugin.version>3.2.2</maven-checkstyle-plugin.version>
    <!--    <maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>-->
    <!--    <checkstyle.version>10.3.2</checkstyle.version>-->
    <checkstyle.version>10.11.0</checkstyle.version>
  </properties>

  <build>
    <plugins>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${maven-checkstyle-plugin.version}</version>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>${checkstyle.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <configLocation>checkstyle.xml</configLocation>
          <encoding>${project.build.sourceEncoding}</encoding>
          <consoleOutput>true</consoleOutput>
          <failsOnError>true</failsOnError>
          <failOnViolation>true</failOnViolation>
          <violationSeverity>warning</violationSeverity>
          <linkXRef>false</linkXRef>
        </configuration>
        <executions>
          <execution>
            <id>validate</id>
            <phase>validate</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
83qze16e

83qze16e1#

I moved the `<dependency>` element from within the `<maven-checkstyle-plugin>` element to the `<dependencies>` element. Now IntelliJ doesn't complain the `<encoding>` element anymore.

此外,现在编码似乎分为<inputEncoding><outputEncoding>

相关问题