sbt / sbt

sbt, the interactive build tool
https://scala-sbt.org
Apache License 2.0
4.81k stars 937 forks source link

Can't Publish Ivy & Maven Metadata Simultaneously #2821

Open m4dc4p opened 8 years ago

m4dc4p commented 8 years ago

The publish task can publish Maven or Ivy metadata, which is controlled by the publishMavenStyle key. If publishMavenStyle is true, then publish creates a POM and uploads it to the repository. Otherwise, it generates an Ivy XML file and uploads that. I want to do both, but SBT makes it really hard.

A workaround is to define a subProject which only publishes the Maven POM, and a root project that publishes Ivy metadata:

lazy val commonSettings = Seq(
  name := "foo",
  organization := "bar",
  publishTo := "repo" at "https://mymixedrepo"
)

lazy val mavenRepo = (project in file("mavenRepo"))
  .settings(commonSettings:_*)
  // Only publish POM
  .settings(publishArtifact in Compile := false)
  .settings(publishMavenStyle := true)

lazy val root = (project in file("."))
    .settings(publishMavenStyle := false)
    .settings(commonSettings:_*)

The mavenRepo project only publishes the POM (publishArtifcat in Compile := false), while the root project publishes all other artifacts, plus Ivy dependencies. To publish, use a two step process:

sbt> ; project mavenRepo; publish; project root; publish

I would like to see a simpler solution to this problem (for example, could publishMavenStyle be a case class that indicates Ivy, Maven, or both?)

eed3si9n commented 8 years ago

A workaround is to define a subProject which only publishes the Maven POM, and a root project that publishes Ivy metadata:

This sounds like a pretty good solution to me. You can aggregate command at the root to make root publish both:

....

lazy val root = (project in file("."))
    .aggregate(mavenRepo)
    .settings(publishMavenStyle := false)
    .settings(commonSettings:_*)
shengc commented 6 years ago
publishMavenStyle := false,
packagedArtifacts += ((artifact in makePom).value, makePom.value)