Class GradleBuildWriter

java.lang.Object
io.spring.initializr.generator.buildsystem.gradle.GradleBuildWriter
Direct Known Subclasses:
GroovyDslGradleBuildWriter, KotlinDslGradleBuildWriter

public abstract class GradleBuildWriter extends Object
GradleBuild writer abstraction.
Author:
Andy Wilkinson, Stephane Nicoll, Jean-Baptiste Nizet, Moritz Halbritter
See Also:
  • Constructor Details

    • GradleBuildWriter

      public GradleBuildWriter()
  • Method Details

    • writeTo

      public final void writeTo(IndentingWriter writer, GradleBuild build)
      Write a build.gradle using the specified writer.
      Parameters:
      writer - the writer to use
      build - the gradle build to write
    • writeBuildscript

      protected abstract void writeBuildscript(IndentingWriter writer, GradleBuild build)
      Write the buildscript block.
      Parameters:
      writer - the writer
      build - the build
    • writePlugins

      protected abstract void writePlugins(IndentingWriter writer, GradleBuild build)
      Write the plugins block.
      Parameters:
      writer - the writer
      build - the build
    • extractStandardPlugin

      protected List<StandardGradlePlugin> extractStandardPlugin(GradleBuild build)
      Return the standard plugins of the build.
      Parameters:
      build - the build
      Returns:
      the standard plugins
    • writeJavaSourceCompatibility

      @Deprecated(forRemoval=true) protected void writeJavaSourceCompatibility(IndentingWriter writer, GradleBuildSettings settings)
      Deprecated, for removal: This API element is subject to removal in a future version.
      for removal in favor of Gradle toolchains
      Writes the source compatibility for Java.
      Parameters:
      writer - the writer
      settings - the settings
    • writeConfigurations

      protected abstract void writeConfigurations(IndentingWriter writer, GradleConfigurationContainer configurations)
      Write the configurations.
      Parameters:
      writer - the writer
      configurations - the configurations
    • writeRepositories

      protected final void writeRepositories(IndentingWriter writer, GradleBuild build)
      Write the repositories block.
      Parameters:
      writer - the writer
      build - the build
    • repositoryAsString

      protected abstract String repositoryAsString(MavenRepository repository)
      Return the string representation of the given repository.
      Parameters:
      repository - the repository
      Returns:
      the repository as string
    • writeExtraProperties

      protected abstract void writeExtraProperties(IndentingWriter writer, Map<String,String> allProperties)
      Write the extra properties.
      Parameters:
      writer - the writer
      allProperties - the properties to write
    • getDependencyComparator

      protected Comparator<Dependency> getDependencyComparator()
      Return the Comparator to use to sort dependencies.
      Returns:
      a dependency comparator
    • writeDependency

      protected abstract void writeDependency(IndentingWriter writer, Dependency dependency)
      Write the given dependency.
      Parameters:
      writer - the writer
      dependency - the dependency
    • configurationForDependency

      protected String configurationForDependency(Dependency dependency)
      Return the configuration to use for the given dependency.
      Parameters:
      dependency - the dependency
      Returns:
      the configuration, for example implementation
    • bomAsString

      protected abstract String bomAsString(BillOfMaterials bom)
      Return the string representation of the given bom.
      Parameters:
      bom - the bom
      Returns:
      the bom as string
    • writeTasks

      protected abstract void writeTasks(IndentingWriter writer, GradleTaskContainer tasks)
      Write the task customizations.
      Parameters:
      writer - the writer
      tasks - the tasks
    • writeTaskCustomization

      protected final void writeTaskCustomization(IndentingWriter writer, GradleTask task)
      Write the invocations, attributes and nested customizations of the given task.
      Parameters:
      writer - the writer
      task - the task
    • invocationAsString

      protected abstract String invocationAsString(Invocation invocation)
      Return the string representation of the given invocation.
      Parameters:
      invocation - the invocation
      Returns:
      the invocation as string
    • writeNestedCollection

      protected final <T> void writeNestedCollection(IndentingWriter writer, String name, Collection<T> collection, Function<T,String> itemToStringConverter)
      Write the given collection in a block with the given name. Does nothing if the collection is empty.
      Type Parameters:
      T - the type of the items
      Parameters:
      writer - the writer
      name - the name of the block
      collection - the collection
      itemToStringConverter - the converter to use for each item
    • writeNestedCollection

      protected final <T> void writeNestedCollection(IndentingWriter writer, String name, Collection<T> collection, Function<T,String> converter, @Nullable Runnable beforeWriting)
      Write the given collection in a block with the given name. Does nothing if the collection is empty.
      Type Parameters:
      T - the type of the items
      Parameters:
      writer - the writer
      name - the name of the block
      collection - the collection
      converter - the converter to use for each item
      beforeWriting - callback to invoke before writing, or null
    • writeCollection

      protected final <T> void writeCollection(IndentingWriter writer, Collection<T> collection, Function<T,String> converter)
      Write each item of the given collection on its own line. Does nothing if the collection is empty.
      Type Parameters:
      T - the type of the items
      Parameters:
      writer - the writer
      collection - the collection
      converter - the converter to use for each item
    • writeCollection

      protected final <T> void writeCollection(IndentingWriter writer, Collection<T> collection, Function<T,String> itemToStringConverter, @Nullable Runnable beforeWriting)
      Write each item of the given collection on its own line. Does nothing if the collection is empty.
      Type Parameters:
      T - the type of the items
      Parameters:
      writer - the writer
      collection - the collection
      itemToStringConverter - the converter to use for each item
      beforeWriting - callback to invoke before writing, or null
    • writeMap

      protected final <T,U> void writeMap(IndentingWriter writer, Map<T,U> map, BiFunction<T,U,String> converter)
      Write each entry of the given map on its own line.
      Type Parameters:
      T - the type of the keys
      U - the type of the values
      Parameters:
      writer - the writer
      map - the map
      converter - the converter to use for each entry
    • writeProperty

      protected abstract void writeProperty(IndentingWriter writer, String name, @Nullable String value)
      Write the given property.
      Parameters:
      writer - the writer
      name - the name of the property
      value - the value of the property