运行docker:publishLocal时如何避免编写pom?

时间:2018-06-24 21:08:06

标签: scala docker build sbt pom.xml

我在build.sbt上有两个子项目,一个子项目依赖于另一个子项目(cli依赖于并聚合核心)。核心将作为库发布,而cli将作为docker映像发布。问题是当我执行cli / docker:publishLocal时我无法避免编写pom ...如何避免这种情况?这是当前的build.sbt文件:

import sbt.Keys._
import sbt._

val scalaBinaryVersionNumber = "2.12"
val scalaVersionNumber = s"$scalaBinaryVersionNumber.4"

resolvers += Resolver.bintrayIvyRepo("sbt", "sbt-plugin-releases")

lazy val aggregatedProjects: Seq[ProjectReference] = Seq(core, cli)

lazy val testDependencies = Dependencies.specs2.map(_ % Test)

lazy val root = project
  .in(file("."))
  .settings(name := "root")
  .settings(inThisBuild(List(
    //Credentials for sonatype
    credentials += Credentials(
      "Sonatype Nexus Repository Manager",
      "oss.sonatype.org",
      sys.env.getOrElse("SONATYPE_USER", "username"),
      sys.env.getOrElse("SONATYPE_PASSWORD", "password")),
    scalaVersion := scalaVersionNumber,
    version := "0.1.0-SNAPSHOT",
    organization := "com.test",
    scalacOptions ++= Common.compilerFlags,
    scalacOptions.in(Test) ++= Seq("-Yrangepos"),
    scalacOptions.in(Compile, console) --= Seq("-Ywarn-unused:imports", "-Xfatal-warnings"))))
  .aggregate(aggregatedProjects: _*)
  .settings(publish := {}, publishLocal := {}, publishArtifact := false)

lazy val core = project
  .in(file("core"))
  .settings(name := "core")
  .settings(
    // App Dependencies
    libraryDependencies ++= Seq(
      Dependencies.caseApp,
      Dependencies.betterFiles,
      Dependencies.jodaTime,
      Dependencies.fansi,
      Dependencies.scalajHttp,
      Dependencies.cats) ++
      Dependencies.circe ++
      Dependencies.jackson ++
      Dependencies.log4s
    // Test Dependencies
    libraryDependencies ++= testDependencies)
  .settings(
    // Sonatype repository settings
    publishMavenStyle := true,
    publishArtifact.in(Test) := false,
    //publishArtifact.in(makePom.in(Docker)) := false,
    publish.in(Docker) := {},
    publishLocal.in(Docker) := {},
    pomIncludeRepository := { _ =>
      false
    },
    publishTo := sonatypePublishTo.value)
  .settings(pomExtra := <scm>
    <url>https://github.com/test</url>
    <connection>scm:git:git@github.com:test.git</connection>
    <developerConnection>scm:git:https://github.com/test.git</developerConnection>
  </scm>)

lazy val cli = project
  .in(file("cli"))
  .enablePlugins(JavaAppPackaging)
  .enablePlugins(DockerPlugin)
  .settings(name := "cli")
  .settings(Common.dockerSettings: _*)
  .settings(Common.genericSettings: _*)
  .settings(
    //publish := publish.in(Docker).value,
    //publishLocal := publishLocal.in(Docker).value,
    publishArtifact := false)
  .settings(libraryDependencies ++= testDependencies)
  .dependsOn(core)
  .aggregate(core)

// Scapegoat
scalaVersion in ThisBuild := scalaVersionNumber
scalaBinaryVersion in ThisBuild := scalaBinaryVersionNumber
scapegoatDisabledInspections in ThisBuild := Seq()
scapegoatVersion in ThisBuild := "1.3.4"

如您所见,我已经尝试在核心设置中添加“ publishArtifact.in(makePom.in(Docker)):= false”,但这在我执行core / publishLocal时不会写pom ...我只是想避免在执行cli / docker:publishLocal时编写pom。

0 个答案:

没有答案