Maven插件学习(三)——插件配置依赖和执行目标

maven-checkstyle-plugin插件的配置

配置了两个依赖和一个执行任务。

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-checkstyle-plugin</artifactId>
	<version>2.17</version>
	<dependencies>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>  <!-- 将commons-logging桥接到 SLF4J -->
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-jdk14</artifactId> <!-- 将SLF4J绑定到JDK的java.util.logging-->

			<version>1.7.5</version>
		</dependency>
	</dependencies>
	<executions>
		<execution>
			<id>checkstyle-validation</id>
			<phase>process-sources</phase>
			<configuration>
				<encoding>UTF-8</encoding>
				<consoleOutput>true</consoleOutput>
				<failsOnError>true</failsOnError>
				<linkXRef>false</linkXRef>
				<configLocation>../checkstyle_checks.xml</configLocation>
			</configuration>
			<goals>
				<goal>check</goal>
			</goals>
		</execution>
	</executions>
</plugin>

执行目标说明

cmd中执行以下命令,查看插件的详细说明

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-checkstyle-plugin:2.17 -Ddetail

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-checkstyle-plugin:2.17 -Ddetail

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.4.0:describe (default-cli) @ standalone-pom ---
[INFO] org.apache.maven.plugins:maven-checkstyle-plugin:2.17

Name: Apache Maven Checkstyle Plugin
Description: Generates a report on violations of code style and optionally
  fails the build if violations are detected.
Group Id: org.apache.maven.plugins
Artifact Id: maven-checkstyle-plugin
Version: 2.17
Goal Prefix: checkstyle

This plugin has 4 goals:

checkstyle:check
  Description: Performs Checkstyle analysis and outputs violations or a count
    of violations to the console, potentially failing the build. It can also be
    configured to re-use an earlier analysis.
  Implementation:
  org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo
  Language: java
  Bound to phase: verify

  Available parameters:

    cacheFile (Default:
    ${project.build.directory}/checkstyle-cachefile)
      Specifies the cache file used to speed up Checkstyle on successive runs.

    checkstyleRules
      By using this property, you can specify the whole Checkstyle rules inline
      directly inside this pom. This feature requires Maven 3+. <plugin> ...
      <configuration> <checkstyleRules> <module name="Checker"> <module
      name="FileTabCharacter"> <property name="eachLine" value="true" />
      </module> <module name="TreeWalker"> <module name="EmptyBlock"/>
      </module> </module> </checkstyleRules> </configuration> ...

    configLocation (Default: sun_checks.xml)
      User property: checkstyle.config.location

      Specifies the location of the XML configuration to use.



      Potential values are a filesystem path, a URL, or a classpath resource.
      This parameter expects that the contents of the location conform to the
      xml format (Checkstyle Checker module
      <http://checkstyle.sourceforge.net/config.html#Modules>) configuration of
      rulesets.



      This parameter is resolved as resource, URL, then file. If successfully
      resolved, the contents of the configuration is copied into the
      ${project.build.directory}/checkstyle-configuration.xml file before being
      passed to Checkstyle as a configuration.



      There are 2 predefined rulesets.

      * sun_checks.xml: Sun Checks.
      * google_checks.xml: Google Checks.

    consoleOutput (Default: false)
      User property: checkstyle.consoleOutput
      Output errors to console.

    encoding (Default: ${project.build.sourceEncoding})
      User property: encoding
      The file encoding to use when reading the source files. If the property
      project.build.sourceEncoding is not set, the platform default encoding is
      used. Note: This parameter always overrides the property charset from
      Checkstyle's TreeWalker module.

    excludes
      User property: checkstyle.excludes
      Specifies the names filter of the source files to be excluded for
      Checkstyle.

    failOnViolation (Default: true)
      User property: checkstyle.failOnViolation
      Fail the build on a violation. The goal checks for the violations after
      logging them (if {@link #logViolationsToConsole} is {@code true}).
      Compare this to {@link #failsOnError} which fails the build immediately
      before examining the output log.

    failsOnError (Default: false)
      If this is true, and Checkstyle reported any violations or errors, the
      build fails immediately after running Checkstyle, before checking the log
      for {@link #logViolationsToConsole}. If you want to use {@link
      #logViolationsToConsole}, use {@link #failOnViolation} instead of this.

    headerLocation (Default: LICENSE.txt)
      User property: checkstyle.header.file

      Specifies the location of the License file (a.k.a. the header file) that
      can be used by Checkstyle to verify that source code has the correct
      license header.

      You need to use ${checkstyle.header.file} in your Checkstyle xml
      configuration to reference the name of this header file.

      For instance:

      <module name="RegexpHeader"> <property name="headerFile"
      value="${checkstyle.header.file}"/> </module>

    includeResources (Default: true)
      Required: true
      User property: checkstyle.includeResources
      Whether to apply Checkstyle to resource directories.

    includes (Default: **\/*.java)
      Required: true
      User property: checkstyle.includes
      Specifies the names filter of the source files to be used for Checkstyle.

    includeTestResources (Default: true)
      Required: true
      User property: checkstyle.includeTestResources
      Whether to apply Checkstyle to test resource directories.

    includeTestSourceDirectory (Default: false)
      Include or not the test source directory to be used for Checkstyle.

    logViolationsToConsole (Default: true)
      User property: checkstyle.console
      Output the detected violations to the console.

    maxAllowedViolations (Default: 0)
      User property: checkstyle.maxAllowedViolations
      The maximum number of allowed violations. The execution fails only if the
      number of violations is above this limit.

    outputFile (Default:
    ${project.build.directory}/checkstyle-result.xml)
      User property: checkstyle.output.file
      Specifies the path and filename to save the Checkstyle output. The format
      of the output file is determined by the outputFileFormat parameter.

    outputFileFormat (Default: xml)
      User property: checkstyle.output.format
      Specifies the format of the output to be used when writing to the output
      file. Valid values are "plain" and "xml".

    propertiesLocation
      User property: checkstyle.properties.location

      Specifies the location of the properties file.



      This parameter is resolved as URL, File then resource. If successfully
      resolved, the contents of the properties location is copied into the
      ${project.build.directory}/checkstyle-checker.properties file before
      being passed to Checkstyle for loading.



      The contents of the propertiesLocation will be made available to
      Checkstyle for specifying values for parameters within the xml
      configuration (specified in the configLocation parameter).

    propertyExpansion
      Allows for specifying raw property expansion information.

    resourceExcludes
      User property: checkstyle.resourceExcludes
      Specifies the names filter of the files to be excluded for Checkstyle
      when checking resources.

    resourceIncludes (Default: **/*.properties)
      Required: true
      User property: checkstyle.resourceIncludes
      Specifies the names filter of the files to be used for Checkstyle when
      checking resources.

    rulesFiles (Default:
    ${project.build.directory}/checkstyle-rules.xml)
      User property: checkstyle.output.rules.file
      dump file for inlined Checkstyle rules

    skip (Default: false)
      User property: checkstyle.skip
      Skip entire check.

    skipExec (Default: false)
      User property: checkstyle.skipExec
      Skip Checkstyle execution will only scan the outputFile.

    sourceDirectories (Default: ${project.compileSourceRoots})
      Specifies the location of the source directories to be used for
      Checkstyle.

    sourceDirectory
      Specifies the location of the source directory to be used for Checkstyle.
      Deprecated. instead use {@link #sourceDirectories}

    suppressionsFileExpression (Default:
    checkstyle.suppressions.file)
      User property: checkstyle.suppression.expression
      The key to be used in the properties for the suppressions file.

    suppressionsLocation
      User property: checkstyle.suppressions.location

      Specifies the location of the suppressions XML file to use.



      This parameter is resolved as resource, URL, then file. If successfully
      resolved, the contents of the suppressions XML is copied into the
      ${project.build.directory}/checkstyle-suppressions.xml file before being
      passed to Checkstyle for loading.



      See suppressionsFileExpression for the property that will be made
      available to your Checkstyle configuration.

    testSourceDirectories (Default:
    ${project.testCompileSourceRoots})
      Specifies the location of the test source directories to be used for
      Checkstyle.

    testSourceDirectory
      Specifies the location of the test source directory to be used for
      Checkstyle.
      Deprecated. instead use {@link #testSourceDirectories}

    useFile
      If null, the Checkstyle plugin will display violations on stdout.
      Otherwise, a text file will be created with the violations.

    violationIgnore
      User property: checkstyle.violation.ignore
      Violations to ignore. This is a comma-separated list, each value being
      either a rule name, a rule category or a java package name of rule class.

    violationSeverity (Default: error)
      User property: checkstyle.violationSeverity
      The lowest severity level that is considered a violation. Valid values
      are "error", "warning" and "info".

checkstyle:checkstyle
  Description: A reporting task that performs Checkstyle analysis and
    generates an HTML report on any violations that Checkstyle finds.
  Note: This goal should be used as a Maven report.
  Implementation: org.apache.maven.plugin.checkstyle.CheckstyleReport
  Language: java

  Available parameters:

    cacheFile (Default:
    ${project.build.directory}/checkstyle-cachefile)
      Specifies the cache file used to speed up Checkstyle on successive runs.

    configLocation (Default: sun_checks.xml)
      User property: checkstyle.config.location

      Specifies the location of the XML configuration to use.



      Potential values are a filesystem path, a URL, or a classpath resource.
      This parameter expects that the contents of the location conform to the
      xml format (Checkstyle Checker module
      <http://checkstyle.sourceforge.net/config.html#Modules>) configuration of
      rulesets.



      This parameter is resolved as resource, URL, then file. If successfully
      resolved, the contents of the configuration is copied into the
      ${project.build.directory}/checkstyle-configuration.xml file before being
      passed to Checkstyle as a configuration.



      There are 2 predefined rulesets included in Maven Checkstyle Plugin:

      * sun_checks.xml: Sun Checks.
      * google_checks.xml: Google Checks.

    consoleOutput (Default: false)
      User property: checkstyle.consoleOutput
      Output errors to console.

    enableFilesSummary (Default: true)
      User property: checkstyle.enable.files.summary
      Specifies if the Files summary should be enabled or not.

    enableRSS (Default: true)
      User property: checkstyle.enable.rss
      Specifies if the RSS should be enabled or not.

    enableRulesSummary (Default: true)
      User property: checkstyle.enable.rules.summary
      Specifies if the Rules summary should be enabled or not.

    enableSeveritySummary (Default: true)
      User property: checkstyle.enable.severity.summary
      Specifies if the Severity summary should be enabled or not.

    encoding (Default: ${project.build.sourceEncoding})
      User property: encoding
      The file encoding to use when reading the source files. If the property
      project.build.sourceEncoding is not set, the platform default encoding is
      used. Note: This parameter always overrides the property charset from
      Checkstyle's TreeWalker module.

    excludes
      User property: checkstyle.excludes
      Specifies the names filter of the source files to be excluded for
      Checkstyle.

    failsOnError (Default: false)
      Specifies if the build should fail upon a violation.

    format (Default: sun)
      Specifies what predefined check set to use. Available sets are "sun" (for
      the Sun coding conventions), and "maven".
      Deprecated. Use configLocation instead.

    headerFile (Default: ${basedir}/LICENSE.txt)
      Specifies the location of the License file (a.k.a. the header file) that
      is used by Checkstyle to verify that source code has the correct license
      header.
      Deprecated. Use headerLocation instead.

    headerLocation (Default: LICENSE.txt)
      User property: checkstyle.header.file

      Specifies the location of the License file (a.k.a. the header file) that
      can be used by Checkstyle to verify that source code has the correct
      license header.

      You need to use ${checkstyle.header.file} in your Checkstyle xml
      configuration to reference the name of this header file.

      For instance:

      <module name="RegexpHeader"> <property name="headerFile"
      value="${checkstyle.header.file}"/> </module>

    includeResources (Default: true)
      Required: true
      User property: checkstyle.includeResources
      Specifies whether to include the resource directories in the check.

    includes (Default: **\/*.java)
      Required: true
      User property: checkstyle.includes
      Specifies the names filter of the source files to be used for Checkstyle.

    includeTestResources (Default: true)
      Required: true
      User property: checkstyle.includeTestResources
      Specifies whether to include the test resource directories in the check.

    includeTestSourceDirectory (Default: false)
      Include or not the test source directory/directories to be used for
      Checkstyle.

    linkXRef (Default: true)
      User property: linkXRef
      Link the violation line numbers to the source xref. Will link
      automatically if Maven JXR plugin is being used.

    outputFile (Default:
    ${project.build.directory}/checkstyle-result.xml)
      User property: checkstyle.output.file
      Specifies the path and filename to save the Checkstyle output. The format
      of the output file is determined by the outputFileFormat parameter.

    outputFileFormat (Default: xml)
      User property: checkstyle.output.format
      Specifies the format of the output to be used when writing to the output
      file. Valid values are "plain" and "xml".

    packageNamesFile
      Specifies the location of the package names XML to be used to configure
      Checkstyle.
      Deprecated. Use packageNamesLocation instead.

    packageNamesLocation

      Specifies the location of the package names XML to be used to configure
      the Checkstyle Packages
      <http://checkstyle.sourceforge.net/config.html#Packages>.



      This parameter is resolved as resource, URL, then file. If resolved to a
      resource, or a URL, the contents of the package names XML is copied into
      the ${project.build.directory}/checkstyle-packagenames.xml file before
      being passed to Checkstyle for loading.

    propertiesFile
      Specifies the location of the Checkstyle properties file that will be
      used to check the source.
      Deprecated. Use propertiesLocation instead.

    propertiesLocation
      User property: checkstyle.properties.location

      Specifies the location of the properties file.



      This parameter is resolved as URL, File then resource. If successfully
      resolved, the contents of the properties location is copied into the
      ${project.build.directory}/checkstyle-checker.properties file before
      being passed to Checkstyle for loading.



      The contents of the propertiesLocation will be made available to
      Checkstyle for specifying values for parameters within the xml
      configuration (specified in the configLocation parameter).

    propertiesURL
      Specifies the URL of the Checkstyle properties that will be used to check
      the source.
      Deprecated. Use propertiesLocation instead.

    propertyExpansion
      Allows for specifying raw property expansion information.

    resourceExcludes
      User property: checkstyle.resourceExcludes
      Specifies the names filter of the resource files to be excluded for
      Checkstyle.

    resourceIncludes (Default: **/*.properties)
      Required: true
      User property: checkstyle.resourceIncludes
      Specifies the names filter of the resource files to be used for
      Checkstyle.

    skip (Default: false)
      User property: checkstyle.skip
      Skip entire check.

    sourceDirectories (Default: ${project.compileSourceRoots})
      Specifies the location of the source directories to be used for
      Checkstyle.

    sourceDirectory
      Specifies the location of the source directory to be used for Checkstyle.
      Deprecated. instead use {@link #sourceDirectories}

    suppressionsFile
      Specifies the location of the suppressions XML file to use. The plugin
      defines a Checkstyle property named checkstyle.suppressions.file with the
      value of this property. This allows using the Checkstyle property in your
      own custom Checkstyle configuration file when specifying a suppressions
      file.
      Deprecated. Use suppressionsLocation instead.

    suppressionsFileExpression (Default:
    checkstyle.suppressions.file)
      User property: checkstyle.suppression.expression
      The key to be used in the properties for the suppressions file.

    suppressionsLocation
      User property: checkstyle.suppressions.location

      Specifies the location of the suppressions XML file to use.



      This parameter is resolved as resource, URL, then file. If successfully
      resolved, the contents of the suppressions XML is copied into the
      ${project.build.directory}/checkstyle-supressions.xml file before being
      passed to Checkstyle for loading.



      See suppressionsFileExpression for the property that will be made
      available to your Checkstyle configuration.

    testSourceDirectories (Default:
    ${project.testCompileSourceRoots})
      Specifies the location of the test source directories to be used for
      Checkstyle.

    testSourceDirectory
      Specifies the location of the test source directory to be used for
      Checkstyle.
      Deprecated. instead use {@link #testSourceDirectories}

    treeWalkerNames
      When using custom treeWalkers, specify their names here so the checks
      inside the treeWalker end up the the rule-summary.

    useFile
      If null, the Checkstyle plugin will display violations on stdout.
      Otherwise, a text file will be created with the violations.

    xrefLocation (Default:
    ${project.reporting.outputDirectory}/xref)
      Location of the Xrefs to link to.

checkstyle:checkstyle-aggregate
  Description: A reporting task that performs Checkstyle analysis and
    generates an aggregate HTML report on the violations that Checkstyle finds
    in a multi-module reactor build.
  Note: This goal should be used as a Maven report.
  Implementation: org.apache.maven.plugin.checkstyle.CheckstyleAggregateReport
  Language: java

  Available parameters:

    cacheFile (Default:
    ${project.build.directory}/checkstyle-cachefile)
      Specifies the cache file used to speed up Checkstyle on successive runs.

    configLocation (Default: sun_checks.xml)
      User property: checkstyle.config.location

      Specifies the location of the XML configuration to use.



      Potential values are a filesystem path, a URL, or a classpath resource.
      This parameter expects that the contents of the location conform to the
      xml format (Checkstyle Checker module
      <http://checkstyle.sourceforge.net/config.html#Modules>) configuration of
      rulesets.



      This parameter is resolved as resource, URL, then file. If successfully
      resolved, the contents of the configuration is copied into the
      ${project.build.directory}/checkstyle-configuration.xml file before being
      passed to Checkstyle as a configuration.



      There are 2 predefined rulesets included in Maven Checkstyle Plugin:

      * sun_checks.xml: Sun Checks.
      * google_checks.xml: Google Checks.

    consoleOutput (Default: false)
      User property: checkstyle.consoleOutput
      Output errors to console.

    enableFilesSummary (Default: true)
      User property: checkstyle.enable.files.summary
      Specifies if the Files summary should be enabled or not.

    enableRSS (Default: true)
      User property: checkstyle.enable.rss
      Specifies if the RSS should be enabled or not.

    enableRulesSummary (Default: true)
      User property: checkstyle.enable.rules.summary
      Specifies if the Rules summary should be enabled or not.

    enableSeveritySummary (Default: true)
      User property: checkstyle.enable.severity.summary
      Specifies if the Severity summary should be enabled or not.

    encoding (Default: ${project.build.sourceEncoding})
      User property: encoding
      The file encoding to use when reading the source files. If the property
      project.build.sourceEncoding is not set, the platform default encoding is
      used. Note: This parameter always overrides the property charset from
      Checkstyle's TreeWalker module.

    excludes
      User property: checkstyle.excludes
      Specifies the names filter of the source files to be excluded for
      Checkstyle.

    failsOnError (Default: false)
      Specifies if the build should fail upon a violation.

    headerLocation (Default: LICENSE.txt)
      User property: checkstyle.header.file

      Specifies the location of the License file (a.k.a. the header file) that
      can be used by Checkstyle to verify that source code has the correct
      license header.

      You need to use ${checkstyle.header.file} in your Checkstyle xml
      configuration to reference the name of this header file.

      For instance:

      <module name="RegexpHeader"> <property name="headerFile"
      value="${checkstyle.header.file}"/> </module>

    includeResources (Default: true)
      Required: true
      User property: checkstyle.includeResources
      Specifies whether to include the resource directories in the check.

    includes (Default: **\/*.java)
      Required: true
      User property: checkstyle.includes
      Specifies the names filter of the source files to be used for Checkstyle.

    includeTestResources (Default: true)
      Required: true
      User property: checkstyle.includeTestResources
      Specifies whether to include the test resource directories in the check.

    includeTestSourceDirectory (Default: false)
      Include or not the test source directory/directories to be used for
      Checkstyle.

    linkXRef (Default: true)
      User property: linkXRef
      Link the violation line numbers to the source xref. Will link
      automatically if Maven JXR plugin is being used.

    outputFile (Default:
    ${project.build.directory}/checkstyle-result.xml)
      User property: checkstyle.output.file
      Specifies the path and filename to save the Checkstyle output. The format
      of the output file is determined by the outputFileFormat parameter.

    outputFileFormat (Default: xml)
      User property: checkstyle.output.format
      Specifies the format of the output to be used when writing to the output
      file. Valid values are "plain" and "xml".

    propertiesLocation
      User property: checkstyle.properties.location

      Specifies the location of the properties file.



      This parameter is resolved as URL, File then resource. If successfully
      resolved, the contents of the properties location is copied into the
      ${project.build.directory}/checkstyle-checker.properties file before
      being passed to Checkstyle for loading.



      The contents of the propertiesLocation will be made available to
      Checkstyle for specifying values for parameters within the xml
      configuration (specified in the configLocation parameter).

    propertyExpansion
      Allows for specifying raw property expansion information.

    resourceExcludes
      User property: checkstyle.resourceExcludes
      Specifies the names filter of the resource files to be excluded for
      Checkstyle.

    resourceIncludes (Default: **/*.properties)
      Required: true
      User property: checkstyle.resourceIncludes
      Specifies the names filter of the resource files to be used for
      Checkstyle.

    skip (Default: false)
      User property: checkstyle.skip
      Skip entire check.

    sourceDirectories (Default: ${project.compileSourceRoots})
      Specifies the location of the source directories to be used for
      Checkstyle.

    sourceDirectory
      Specifies the location of the source directory to be used for Checkstyle.
      Deprecated. instead use {@link #sourceDirectories}

    suppressionsFileExpression (Default:
    checkstyle.suppressions.file)
      User property: checkstyle.suppression.expression
      The key to be used in the properties for the suppressions file.

    suppressionsLocation
      User property: checkstyle.suppressions.location

      Specifies the location of the suppressions XML file to use.



      This parameter is resolved as resource, URL, then file. If successfully
      resolved, the contents of the suppressions XML is copied into the
      ${project.build.directory}/checkstyle-supressions.xml file before being
      passed to Checkstyle for loading.



      See suppressionsFileExpression for the property that will be made
      available to your Checkstyle configuration.

    testSourceDirectories (Default:
    ${project.testCompileSourceRoots})
      Specifies the location of the test source directories to be used for
      Checkstyle.

    testSourceDirectory
      Specifies the location of the test source directory to be used for
      Checkstyle.
      Deprecated. instead use {@link #testSourceDirectories}

    treeWalkerNames
      When using custom treeWalkers, specify their names here so the checks
      inside the treeWalker end up the the rule-summary.

    useFile
      If null, the Checkstyle plugin will display violations on stdout.
      Otherwise, a text file will be created with the violations.

    xrefLocation (Default:
    ${project.reporting.outputDirectory}/xref)
      Location of the Xrefs to link to.

checkstyle:help
  Description: Display help information on maven-checkstyle-plugin.
    Call mvn checkstyle:help -Ddetail=true -Dgoal=<goal-name> to display
    parameter details.
  Implementation: org.apache.maven.plugin.checkstyle.HelpMojo
  Language: java

  Available parameters:

    detail (Default: false)
      User property: detail
      If true, display all settable properties for each goal.

    goal
      User property: goal
      The name of the goal for which to show help. If unspecified, all goals
      will be displayed.

    indentSize (Default: 2)
      User property: indentSize
      The number of spaces per indentation level, should be positive.

    lineLength (Default: 80)
      User property: lineLength
      The maximum length of a display line, should be positive.


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18.494 s
[INFO] Finished at: 2025-04-22T10:32:23+08:00
[INFO] ------------------------------------------------------------------------

根据插件的说明可以看到插件的前缀是checkstyle,有4个目标

checkstyle:check  绑定到default生命周期的verify阶段

checkstyle:checkstyle  没有默认绑定

checkstyle:checkstyle-aggregate 没有默认绑定

checkstyle:help 没有默认绑定

插件中excution执行 checkstyle:check 目标,对源代码进行静态代码检查,将插件执行绑定到 Maven 生命周期的 process-sources 阶段(即编译前),如果不配置 <execution>,插件会绑定到 verify 生命周期阶段。此处显式声明后,会覆盖默认绑定。configuration指定了excution的配置

<configuration>
    <encoding>UTF-8</encoding>          <!-- 指定文件编码 -->
    <consoleOutput>true</consoleOutput>  <!-- 在控制台输出检查结果 -->
    <failsOnError>true</failsOnError>    <!-- 检查失败时终止构建 -->
    <linkXRef>false</linkXRef>          <!-- 不生成交叉引用报告 -->
    <configLocation>../checkstyle_checks.xml</configLocation>  <!-- 规则文件路径 -->
</configuration>

配置依赖说明

强制 maven-checkstyle-plugin 使用特定的日志框架组合,避免因日志实现冲突导致插件执行异常或无日志输出。

什么鬼情况下Maven插件配置中需要单独声明 <dependencies> 呢?

1. 覆盖插件默认的依赖版本

插件的默认依赖可能:

  • 版本过旧(存在安全漏洞或需要新特性)

  • 版本冲突(与项目其他依赖不兼容)

2. 添加插件缺失的依赖

某些插件可能:

  • 按需加载依赖(未包含在默认打包中)

  • 需要额外库支持(如数据库驱动、扩展工具)

示例场景
如果 maven-checkstyle-plugin 需要连接数据库校验规则,但未内置 JDBC 驱动,就需要手动添加:

<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.28</version>
    </dependency>
</dependencies>

3. 解决类加载隔离问题

Maven 插件的依赖与项目依赖是隔离的(避免冲突)。如果插件需要访问项目中的类或第三方库,必须显式声明依赖。

maven-checkstyle-plugin中jcl-over-slf4j 和 slf4j-jdk14 是为了:

  • 统一日志框架(避免插件使用 commons-logging,而是重定向到 SLF4J

  • 确保插件日志输出与项目一致(如都输出到 java.util.logging)。

4. 替换插件的默认实现

某些插件允许通过依赖替换核心组件。例如:

  • 替换代码分析器的规则引擎

  • 更换模板渲染工具

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

螺旋小蜗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值