From 48b7c5d131e695ea31cda2a04bc270c459dce47f Mon Sep 17 00:00:00 2001 From: Guylian Date: Thu, 24 Jan 2019 14:03:49 +0100 Subject: [PATCH 1/3] Attempt to move docker-client dependency back to the provided scope --- build.sbt | 16 +++------ .../docker/DockerSpotifyClientPlugin.scala | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/build.sbt b/build.sbt index e2b86845a..3b8eb06f9 100644 --- a/build.sbt +++ b/build.sbt @@ -12,6 +12,10 @@ javacOptions ++= Seq("-source", "1.8", "-target", "1.8") // put jdeb on the classpath for scripted tests classpathTypes += "maven-plugin" libraryDependencies ++= Seq( + // these dependencies have to be explicitly added by the user + "com.spotify" % "docker-client" % "8.14.3" % Provided, + "org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar"), + "org.apache.commons" % "commons-compress" % "1.18", // for jdkpackager "org.apache.ant" % "ant" % "1.10.5", @@ -23,17 +27,7 @@ libraryDependencies ++= { (pluginCrossBuild / sbtVersion).value match { case v if v.startsWith("1.") => Seq( - "org.scala-sbt" %% "io" % "1.2.2", - // these dependencies have to be explicitly added by the user - // FIXME temporary remove the 'provided' scope. SBT 1.0.0-M6 changed the resolving somehow - "com.spotify" % "docker-client" % "8.14.3" /* % "provided" */, - "org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar") - ) - case _ => - Seq( - // these dependencies have to be explicitly added by the user - "com.spotify" % "docker-client" % "8.14.3" % Provided, - "org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar") + "org.scala-sbt" %% "io" % "1.2.2" ) } } diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala index 2f018098e..5df249cd6 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala @@ -2,10 +2,8 @@ package com.typesafe.sbt.packager.docker import java.nio.file.Paths -import com.spotify.docker.client.DockerClient.BuildParam -import com.spotify.docker.client.messages.ProgressMessage -import com.spotify.docker.client.{DefaultDockerClient, DockerClient, ProgressHandler} import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.stage + import sbt.Keys._ import sbt._ @@ -63,6 +61,35 @@ object DockerSpotifyClientPlugin extends AutoPlugin { val log = streams.value.log val dockerDirectory = context.toString + + val docker = new DockerClientTask() + docker.packageDocker(primaryAlias, aliases, dockerDirectory, log) + } + + def dockerServerVersion: Def.Initialize[Task[Option[DockerVersion]]] = Def.task { + val docker = new DockerClientTask() + docker.dockerServerVersion() + } + +} + +/** + * == Docker Client Task == + * + * This private class contains all the docker-plugin specific implementations. It's only invoked when the docker + * plugin is enabled and the `docker:publishLocal` task is called. This means that all classes in + * `com.spotify.docker.client._` are only loaded when required and allows us to put the dependency in the "provided" + * scope. The provided scope means that we have less dependency issues in an sbt build. + */ +private class DockerClientTask { + import com.spotify.docker.client.DockerClient.BuildParam + import com.spotify.docker.client.messages.ProgressMessage + import com.spotify.docker.client.{DefaultDockerClient, DockerClient, ProgressHandler} + + def packageDocker(primaryAlias: DockerAlias, + aliases: Seq[DockerAlias], + dockerDirectory: String, + log: Logger): Unit = { val docker: DockerClient = DefaultDockerClient.fromEnv().build() log.info(s"PublishLocal using Docker API ${docker.version().apiVersion()}") @@ -80,9 +107,8 @@ object DockerSpotifyClientPlugin extends AutoPlugin { } } - def dockerServerVersion: Def.Initialize[Task[Option[DockerVersion]]] = Def.task { + def dockerServerVersion(): Option[DockerVersion] = { val docker: DockerClient = DefaultDockerClient.fromEnv().build() DockerVersion.parse(docker.version().version()) } - } From ad308f2ff9e53f5f3fc0accd171761e6fff993db Mon Sep 17 00:00:00 2001 From: Guylian Date: Fri, 25 Jan 2019 10:03:17 +0100 Subject: [PATCH 2/3] Fix crossbuilding --- build.sbt | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sbt b/build.sbt index 3b8eb06f9..4ef2effce 100644 --- a/build.sbt +++ b/build.sbt @@ -29,6 +29,7 @@ libraryDependencies ++= { Seq( "org.scala-sbt" %% "io" % "1.2.2" ) + case _ => Seq() } } From 5de0c47f6d1e943ec8c3cad9df8600aca31a12ad Mon Sep 17 00:00:00 2001 From: Guylian Date: Fri, 25 Jan 2019 10:04:17 +0100 Subject: [PATCH 3/3] Formatting --- build.sbt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 4ef2effce..b3f7ec23e 100644 --- a/build.sbt +++ b/build.sbt @@ -15,7 +15,6 @@ libraryDependencies ++= Seq( // these dependencies have to be explicitly added by the user "com.spotify" % "docker-client" % "8.14.3" % Provided, "org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar"), - "org.apache.commons" % "commons-compress" % "1.18", // for jdkpackager "org.apache.ant" % "ant" % "1.10.5", @@ -26,9 +25,7 @@ libraryDependencies ++= Seq( libraryDependencies ++= { (pluginCrossBuild / sbtVersion).value match { case v if v.startsWith("1.") => - Seq( - "org.scala-sbt" %% "io" % "1.2.2" - ) + Seq("org.scala-sbt" %% "io" % "1.2.2") case _ => Seq() } }