Class SmithyFormatCheckTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
software.amazon.smithy.gradle.tasks.SmithyFormatTask
software.amazon.smithy.gradle.tasks.SmithyFormatCheckTask
All Implemented Interfaces:
Comparable<org.gradle.api.Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, org.gradle.api.Named, org.gradle.api.plugins.ExtensionAware, org.gradle.api.Task, org.gradle.util.Configurable<org.gradle.api.Task>

@DisableCachingByDefault(because="Only verifies formatting and has no cacheable outputs") public abstract class SmithyFormatCheckTask extends SmithyFormatTask
Verifies that Smithy source files are already formatted without modifying them.

This task passes --check to the Smithy CLI format command. Source files are left untouched; the build fails if any file is not already formatted. This is intended for CI pipelines that want to enforce consistent formatting.

Unlike SmithyFormatTask, this task is not wired into the build lifecycle by default. Wire it into the check task or invoke it explicitly in CI:


 ./gradlew smithyFormatCheck
 

Requires Smithy CLI version 1.72.0 or later.

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Named

    org.gradle.api.Named.Namer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.gradle.api.model.ObjectFactory
    Object factory used to create new gradle domain objects such as FileCollections.

    Fields inherited from interface org.gradle.api.Task

    TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
  • Constructor Summary

    Constructors
    Constructor
    Description
    SmithyFormatCheckTask(org.gradle.api.model.ObjectFactory objectFactory, org.gradle.StartParameter startParameter)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Add --stacktrace and --logging settings based on Gradle's settings.
    void
     
    protected void
    executeCliProcess(String command, List<String> additionalArgs, org.gradle.api.file.FileCollection sources, boolean disableModelDiscovery)
    Executes the given CLI command.
    abstract org.gradle.api.provider.Property<Boolean>
    Sets whether to fail a Smithy CLI task if an unknown trait is encountered.
    abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection>
    Classpath to use for build dependencies.
    abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection>
    Base classpath used for executing the smithy cli.
    abstract org.gradle.api.provider.Property<Boolean>
    Whether to fork a new process for executing the smithy cli.
    abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection>
    Classpath used for discovery of additional Smithy models during cli execution.
    abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection>
    Gets the list of models to execute a CLI command on.
    abstract org.gradle.api.provider.Property<org.gradle.api.logging.configuration.ShowStacktrace>
    Sets the detail to include in stack traces.
    protected void
    Writes header-formatted text to the build output.

    Methods inherited from class software.amazon.smithy.gradle.tasks.SmithyFormatTask

    formatModels

    Methods inherited from class org.gradle.api.DefaultTask

    compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService

    Methods inherited from class org.gradle.api.internal.AbstractTask

    acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.gradle.api.Task

    doNotTrackState, notCompatibleWithConfigurationCache
  • Field Details

    • objectFactory

      protected final org.gradle.api.model.ObjectFactory objectFactory
      Object factory used to create new gradle domain objects such as FileCollections.
  • Constructor Details

    • SmithyFormatCheckTask

      @Inject public SmithyFormatCheckTask(org.gradle.api.model.ObjectFactory objectFactory, org.gradle.StartParameter startParameter)
  • Method Details

    • execute

      public void execute()
      Overrides:
      execute in class SmithyFormatTask
    • getCliClasspath

      @Classpath public abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection> getCliClasspath()
      Base classpath used for executing the smithy cli.

      Note: this classpath must contain the smithy-cli jar.

    • getAllowUnknownTraits

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getAllowUnknownTraits()
      Sets whether to fail a Smithy CLI task if an unknown trait is encountered.

      Defaults to false

      Returns:
      flag indicating state of allowUnknownTraits setting
    • getModelDiscoveryClasspath

      @Classpath @Optional public abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection> getModelDiscoveryClasspath()
      Classpath used for discovery of additional Smithy models during cli execution.

      Defaults to an empty collection.

    • getBuildClasspath

      @Classpath @Optional public abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection> getBuildClasspath()
      Classpath to use for build dependencies.
    • getModels

      @InputFiles @Optional @PathSensitive(RELATIVE) public abstract org.gradle.api.provider.Property<org.gradle.api.file.FileCollection> getModels()
      Gets the list of models to execute a CLI command on.

      These models are also considered "sources" when building a JAR for a project. A source model is a model that appears in the META-INF/smithy directory of a JAR.

      This method will return an empty FileCollection and never null.

      Returns:
      Returns the models to validate.
    • getFork

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getFork()
      Whether to fork a new process for executing the smithy cli.

      If false, the smithy cli will be executed in a new thread instead of a new process

      Defaults to false

      Returns:
      flag indicating fork setting.
    • getShowStackTrace

      @Input @Optional public abstract org.gradle.api.provider.Property<org.gradle.api.logging.configuration.ShowStacktrace> getShowStackTrace()
      Sets the detail to include in stack traces.

      Defaults to ShowStacktrace.INTERNAL_EXCEPTIONS

      Returns:
      stack trace setting.
    • executeCliProcess

      protected void executeCliProcess(String command, List<String> additionalArgs, org.gradle.api.file.FileCollection sources, boolean disableModelDiscovery)
      Executes the given CLI command.

      This method will take care of adding --discover, --discover-classpath, and --allow-unknown-traits.

      Parameters:
      command - The command to execute.
      additionalArgs - Custom arguments that aren't one of the shared args.
      sources - Source files to execute the command on
    • writeHeading

      protected void writeHeading(String text)
      Writes header-formatted text to the build output.
      Parameters:
      text - text to write as a header.
    • configureLoggingOptions

      protected void configureLoggingOptions(List<String> args)
      Add --stacktrace and --logging settings based on Gradle's settings.