Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope dependency unpacking with scala version #202

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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
Expand All @@ -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,
Expand Down
18 changes: 14 additions & 4 deletions src/sbt-test/sbt-avro/publishing/build.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand All @@ -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"
)
17 changes: 15 additions & 2 deletions src/sbt-test/sbt-avro/publishing/test
Original file line number Diff line number Diff line change
Expand Up @@ -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