diff --git a/src/main/scala/com/github/sbt/avro/SbtAvro.scala b/src/main/scala/com/github/sbt/avro/SbtAvro.scala index a83ffe4..62d5103 100644 --- a/src/main/scala/com/github/sbt/avro/SbtAvro.scala +++ b/src/main/scala/com/github/sbt/avro/SbtAvro.scala @@ -124,14 +124,17 @@ object SbtAvro extends AutoPlugin { override lazy val projectSettings: Seq[Setting[_]] = defaultSettings ++ Seq(Compile, Test).flatMap(c => inConfig(c)(configScopedSettings)) - private def unpack(deps: Seq[File], - extractTarget: File, - includeFilter: FileFilter, - excludeFilter: FileFilter, - streams: TaskStreams): Seq[File] = { + private def unpack( + cacheBaseDirectory: File, + deps: Seq[File], + extractTarget: File, + includeFilter: FileFilter, + excludeFilter: FileFilter, + streams: TaskStreams + ): Seq[File] = { def cachedExtractDep(jar: File): Seq[File] = { val cached = FileFunction.cached( - streams.cacheDirectory / jar.name, + cacheBaseDirectory / jar.name, inStyle = FilesInfo.lastModified, outStyle = FilesInfo.exists ) { deps => @@ -157,6 +160,13 @@ object SbtAvro extends AutoPlugin { } private def unpackDependenciesTask(key: TaskKey[Seq[File]]) = Def.task { + val cacheBaseDirectory = Defaults.makeCrossTarget( + streams.value.cacheDirectory, + scalaBinaryVersion.value, + (pluginCrossBuild / sbtBinaryVersion).value, + sbtPlugin.value, + crossPaths.value + ) val conf = configuration.value.toConfigRef val avroArtifacts = update .value @@ -165,6 +175,7 @@ object SbtAvro extends AutoPlugin { .collect { case (`conf`, _, _, file) => file } unpack( + cacheBaseDirectory = cacheBaseDirectory, deps = avroArtifacts, extractTarget = (key / target).value, includeFilter = (key / includeFilter).value, diff --git a/src/sbt-test/sbt-avro/publishing/build.sbt b/src/sbt-test/sbt-avro/publishing/build.sbt index 0a267a7..6ea7eeb 100644 --- a/src/sbt-test/sbt-avro/publishing/build.sbt +++ b/src/sbt-test/sbt-avro/publishing/build.sbt @@ -1,18 +1,26 @@ lazy val commonSettings = Seq( organization := "com.github.sbt", publishTo := Some(Opts.resolver.sonatypeReleases), - scalaVersion := "2.13.11", + scalaVersion := "2.13.15", libraryDependencies ++= Seq( "org.apache.avro" % "avro" % avroCompilerVersion ) ) +lazy val javaOnlySettings = Seq( + crossScalaVersions := Seq.empty, + crossPaths := false, + autoScalaLibrary := false, +) + lazy val `external`: Project = project .in(file("external")) .settings(commonSettings) + .settings(javaOnlySettings) .settings( name := "external", version := "0.0.1-SNAPSHOT", + crossScalaVersions := Seq.empty, crossPaths := false, autoScalaLibrary := false, Compile / packageAvro / publishArtifact := true @@ -21,6 +29,7 @@ lazy val `external`: Project = project lazy val `transitive`: Project = project .in(file("transitive")) .settings(commonSettings) + .settings(javaOnlySettings) .settings( name := "transitive", version := "0.0.1-SNAPSHOT", @@ -36,13 +45,14 @@ lazy val root: Project = project .settings(commonSettings) .settings( name := "publishing-test", + crossScalaVersions := Seq("2.13.15", "2.12.20"), libraryDependencies ++= Seq( - "com.github.sbt" %% "transitive" % "0.0.1-SNAPSHOT" classifier "avro", - "com.github.sbt" %% "transitive" % "0.0.1-SNAPSHOT" % Test classifier "tests", + "com.github.sbt" % "transitive" % "0.0.1-SNAPSHOT" classifier "avro", + "com.github.sbt" % "transitive" % "0.0.1-SNAPSHOT" % Test classifier "tests", "org.specs2" %% "specs2-core" % "4.20.8" % Test ), // add additional transitive test jar - avroDependencyIncludeFilter := avroDependencyIncludeFilter.value || artifactFilter(name = "transitive_2.13", classifier = "tests"), + avroDependencyIncludeFilter := avroDependencyIncludeFilter.value || artifactFilter(name = "transitive", classifier = "tests"), // exclude specific avsc file Compile / avroUnpackDependencies / excludeFilter := (Compile / avroUnpackDependencies / excludeFilter).value || "exclude.avsc" ) diff --git a/src/sbt-test/sbt-avro/publishing/test b/src/sbt-test/sbt-avro/publishing/test index 1947057..c4c3c66 100644 --- a/src/sbt-test/sbt-avro/publishing/test +++ b/src/sbt-test/sbt-avro/publishing/test @@ -24,17 +24,30 @@ $ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/te $ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/external/Avsc.java $ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/transitive/Avsc.java -> compile +> +compile $ exists target/scala-2.13/classes/com/github/sbt/avro/test/external/Avdl.class $ exists target/scala-2.13/classes/com/github/sbt/avro/test/external/Avpr.class $ exists target/scala-2.13/classes/com/github/sbt/avro/test/external/Avsc.class $ exists target/scala-2.13/classes/com/github/sbt/avro/test/transitive/Avsc.class -> Test/compile + +$ exists target/scala-2.12/classes/com/github/sbt/avro/test/external/Avdl.class +$ exists target/scala-2.12/classes/com/github/sbt/avro/test/external/Avpr.class +$ exists target/scala-2.12/classes/com/github/sbt/avro/test/external/Avsc.class +$ exists target/scala-2.12/classes/com/github/sbt/avro/test/transitive/Avsc.class + +> Test/avroUnpackDependencies $ exists target/scala-2.13/src_managed/avro/test/test.avsc + +> Test/avroGenerate + $ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/transitive/Test.java + +> +Test/compile + $ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/transitive/Test.class +$ exists target/scala-2.12/test-classes/com/github/sbt/avro/test/transitive/Test.class > clean