diff --git a/README.md b/README.md index 84aa974..56b1ddf 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For instance, add the following lines to `project/plugins.sbt`: addSbtPlugin("com.github.sbt" % "sbt-avro" % "3.5.0") ``` -Enable the plugin in your `build.sbt` and select the avro version to use: +Enable the plugin in your `build.sbt` and select the desired avro version to use: ``` enablePlugins(SbtAvro) @@ -34,31 +34,42 @@ to generate the avro classes. ## Settings -| Name | Default | Description | -|:-------------------------------------------|:----------------------------------------------|:----------------------------------------------------------------------------------------| -| `avroSources` | `sourceDirectory` / `avro` | Source directories with `*.avsc`, `*.avdl` and `*.avpr` files. | -| `avroAdditionalDependencies` | `avro-compiler` % `avro`, `avro` % `compile` | Additional dependencies to be added to library dependencies. | -| `avroSpecificRecords` | `Seq.empty` | List of avro generated classes to recompile with current avro version and settings. | -| `avroUnpackDependencies` / `includeFilter` | All avro specifications | Avro specification files from dependencies to unpack | -| `avroUnpackDependencies` / `excludeFilter` | Hidden files | Avro specification files from dependencies to exclude from unpacking | -| `avroUnpackDependencies` / `target` | `sourceManaged` / `avro` / `$config` | Target directory for schemas packaged in the dependencies | -| `avroGenerate` / `target` | `sourceManaged` / `compiled_avro` / `$config` | Source directory for generated `.java` files. | -| `avroDependencyIncludeFilter` | `source` typed `avro` classifier artifacts | Dependencies containing avro schema to be unpacked for generation | -| `packageAvro` / `artifactClassifier` | `Some("avro")` | Classifier for avro artifact | -| `packageAvro` / `publishArtifact` | `false` | Enable / Disable avro artifact publishing | -| `avroCompiler` | `com.github.sbt.avro.AvroCompilerBridge` | Sbt avro compiler class. | -| `avroStringType` | `CharSequence` | Type for representing strings. Possible values: `CharSequence`, `String`, `Utf8`. | -| `avroUseNamespace` | `false` | Validate that directory layout reflects namespaces, i.e. `com/myorg/MyRecord.avsc`. | -| `avroFieldVisibility` | `public` | Field Visibility for the properties. Possible values: `private`, `public`. | -| `avroEnableDecimalLogicalType` | `true` | Use `java.math.BigDecimal` instead of `java.nio.ByteBuffer` for logical type `decimal`. | -| `avroOptionalGetters` | `false` (requires avro `1.10+`) | Generate getters that return `Optional` for nullable fields. | - -## Tasks +### Project settings + +| Name | Default | Description | +|:-------------------------------|:-------------------------------------------------------------------------|:----------------------------------------------------------------------------------------| +| `avroAdditionalDependencies` | `avro-compiler % avroVersion % "avro"`, `avro % avroVersion % "compile"` | Additional dependencies to be added to library dependencies. | +| `avroCompiler` | `com.github.sbt.avro.AvroCompilerBridge` | Sbt avro compiler class. | +| `avroCreateSetters` | `true` | Generate setters. | +| `avroDependencyIncludeFilter` | `source` typed `avro` classifier artifacts | Filter for including modules containing avro dependencies. | +| `avroEnableDecimalLogicalType` | `true` | Use `java.math.BigDecimal` instead of `java.nio.ByteBuffer` for logical type `decimal`. | +| `avroFieldVisibility` | `public` | Field visibility for the properties. Possible values: `private`, `public`. | +| `avroOptionalGetters` | `false` (requires avro `1.10+`) | Generate getters that return `Optional` for nullable fields. | +| `avroStringType` | `CharSequence` | Type for representing strings. Possible values: `CharSequence`, `String`, `Utf8`. | +| `avroUseNamespace` | `false` | Validate that directory layout reflects namespaces, i.e. `com/myorg/MyRecord.avsc`. | +| `avroVersion` | `1.12.0` | Avro version to use in the project. | + +### Scoped settings (Compile/Test) + +| Name | Default | Description | +|:-------------------------------------------|:----------------------------------------------|:-----------------------------------------------------------------------------------------------------| +| `avroGenerate` / `target` | `sourceManaged` / `compiled_avro` / `$config` | Source directory for generated `.java` files. | +| `avroSource` | `sourceDirectory` / `$config` / `avro` | Default Avro source directory for `*.avsc`, `*.avdl` and `*.avpr` files. | +| `avroSpecificRecords` | `Seq.empty` | List of fully qualified Avro record class names to recompile with current avro version and settings. | +| `avroUmanagedSourceDirectories` | `Seq(avroSource)` | Unmanaged Avro source directories, which contain manually created sources. | +| `avroUnpackDependencies` / `excludeFilter` | `HiddenFileFilter` | Filter for excluding avro specification files from unpacking. | +| `avroUnpackDependencies` / `includeFilter` | `AllPassFilter` | Filter for including avro specification files to unpack. | +| `avroUnpackDependencies` / `target` | `sourceManaged` / `avro` / `$config` | Target directory for schemas packaged in the dependencies | +| `packageAvro` / `artifactClassifier` | `Some("avro")` | Classifier for avro artifact | +| `packageAvro` / `publishArtifact` | `false` | Enable / Disable avro artifact publishing | + + +## Scoped Tasks (Compile/Test) | Name | Description | |:-------------------------|:--------------------------------------------------------------------------------------------------| -| `avroUnpackDependencies` | Unpack avro schemas from dependencies. This task is automatically executed before `avroGenerate`. | | `avroGenerate` | Generate Java sources for Avro schemas. This task is automatically executed before `compile`. | +| `avroUnpackDependencies` | Unpack avro schemas from dependencies. This task is automatically executed before `avroGenerate`. | | `packageAvro` | Produces an avro artifact, such as a jar containing avro schemas. | ## Examples diff --git a/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala b/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala index 9d40a80..108dbb1 100644 --- a/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala +++ b/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala @@ -29,20 +29,21 @@ object SbtAvro extends AutoPlugin { // format: off val avroAdditionalDependencies = settingKey[Seq[ModuleID]]("Additional dependencies to be added to library dependencies.") - val avroCompiler = settingKey[String]("Sbt avro compiler class. Default: com.github.sbt.avro.AvroCompilerBridge") - val avroCreateSetters = settingKey[Boolean]("Generate setters. Default: true") + val avroCompiler = settingKey[String]("Sbt avro compiler class.") + val avroCreateSetters = settingKey[Boolean]("Generate setters.") val avroDependencyIncludeFilter = settingKey[DependencyFilter]("Filter for including modules containing avro dependencies.") - val avroEnableDecimalLogicalType = settingKey[Boolean]("Use java.math.BigDecimal instead of java.nio.ByteBuffer for logical type \"decimal\". Default: true.") - val avroFieldVisibility = settingKey[String]("Field visibility for the properties. Possible values: private, public. Default: public.") - val avroOptionalGetters = settingKey[Boolean]("Generate getters that return Optional for nullable fields. Default: false.") - val avroSpecificRecords = settingKey[Seq[String]]("List of avro records to recompile with current avro version and settings. Classes must be part of the Avro library dependencies.") - val avroSources = settingKey[Seq[File]]("Avro source directories.") - val avroStringType = settingKey[String]("Type for representing strings. Possible values: CharSequence, String, Utf8. Default: CharSequence.") - val avroUnpackDependencies = taskKey[Seq[File]]("Unpack avro dependencies.") - val avroUseNamespace = settingKey[Boolean]("Validate that directory layout reflects namespaces, i.e. src/main/avro/com/myorg/MyRecord.avsc. Default: false.") - val avroVersion = settingKey[String]("Avro version to use in the project. default: 1.12.0") + val avroEnableDecimalLogicalType = settingKey[Boolean]("Use java.math.BigDecimal instead of java.nio.ByteBuffer for logical type decimal.") + val avroFieldVisibility = settingKey[String]("Field visibility for the properties. Possible values: private, public.") + val avroOptionalGetters = settingKey[Boolean]("Generate getters that return Optional for nullable fields.") + val avroSpecificRecords = settingKey[Seq[String]]("List of fully qualified Avro record class names to recompile with current avro version and settings. Classes must be part of the Avro library dependencies scope.") + val avroSource = settingKey[File]("Default Avro source directory for *.avsc, *.avdl and *.avpr files.") + val avroStringType = settingKey[String]("Type for representing strings. Possible values: CharSequence, String, Utf8.") + val avroUnmanagedSourceDirectories = settingKey[Seq[File]]("Unmanaged Avro source directories, which contain manually created sources.") + val avroUseNamespace = settingKey[Boolean]("Validate that directory layout reflects namespaces, i.e. com/myorg/MyRecord.avsc.") + val avroVersion = settingKey[String]("Avro version to use in the project.") val avroGenerate = taskKey[Seq[File]]("Generate Java sources for Avro schemas.") + val avroUnpackDependencies = taskKey[Seq[File]]("Unpack avro dependencies.") val packageAvro = taskKey[File]("Produces an avro artifact, such as a jar containing avro schemas.") // format: on @@ -79,7 +80,8 @@ object SbtAvro extends AutoPlugin { // settings to be applied for both Compile and Test lazy val configScopedSettings: Seq[Setting[_]] = Seq( - avroSources := Seq(sourceDirectory.value / "avro"), + avroSource := sourceDirectory.value / "avro", + avroUnmanagedSourceDirectories := Seq(avroSource.value), avroSpecificRecords := Seq.empty, // dependencies avroUnpackDependencies / includeFilter := AllPassFilter, @@ -103,7 +105,7 @@ object SbtAvro extends AutoPlugin { import autoImport._ def packageAvroMappings: Def.Initialize[Task[Seq[(File, String)]]] = Def.task { - avroSources.value.flatMap(src => (src ** AvroFilter).pair(relativeTo(src))) + avroUnmanagedSourceDirectories.value.flatMap(src => (src ** AvroFilter).pair(relativeTo(src))) } override def trigger: PluginTrigger = noTrigger @@ -168,7 +170,7 @@ object SbtAvro extends AutoPlugin { private def sourceGeneratorTask(key: TaskKey[Seq[File]]) = Def.task { val out = (key / streams).value val externalSrcDir = (avroUnpackDependencies / target).value - val srcDirs = Seq(externalSrcDir) ++ avroSources.value + val srcDirs = avroUnmanagedSourceDirectories.value :+ externalSrcDir val outDir = (key / target).value val cachedCompile = { diff --git a/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala b/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala index c7028ca..eefba9a 100644 --- a/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala +++ b/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala @@ -14,10 +14,10 @@ case class Avro(version: String) extends Platform { .enablePlugins(SbtAvro) .settings( avroVersion := version, - Compile / avroSources ++= crossProjectCrossType.value + Compile / avroUnmanagedSourceDirectories ++= crossProjectCrossType.value .sharedSrcDir(baseDirectory.value, "main") .map(_.getParentFile / "avro"), - Test / avroSources ++= crossProjectCrossType.value + Test / avroUnmanagedSourceDirectories ++= crossProjectCrossType.value .sharedSrcDir(baseDirectory.value, "test") .map(_.getParentFile / "avro"), ) diff --git a/plugin/src/sbt-test/sbt-avro/settings/build.sbt b/plugin/src/sbt-test/sbt-avro/settings/build.sbt index 8e6290d..4442f2c 100644 --- a/plugin/src/sbt-test/sbt-avro/settings/build.sbt +++ b/plugin/src/sbt-test/sbt-avro/settings/build.sbt @@ -13,5 +13,5 @@ avroFieldVisibility := "public" avroOptionalGetters := true avroEnableDecimalLogicalType := false Compile / avroSpecificRecords += "org.apache.avro.specific.TestRecordWithLogicalTypes" -Compile / avroSources += (Compile / sourceDirectory).value / "avro_source" +Compile / avroSource := (Compile / sourceDirectory).value / "avro_source" Compile / avroGenerate / target := (Compile / sourceManaged).value