0
votes

I try to publish a custom artifact to JFrog artifactory from SBT. I have the following project: SBT version 1.4.3

project/plugins.sbt:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")

build.sbt (I simplified a bit the actual one)

ThisBuild / scalaVersion := "2.11.12"
ThisBuild / organization := "my.org"
ThisBuild / organizationName := "company"

lazy val root = (project in file(".")).settings(
   name := "my-project"
)

publishTo := {
  val artifactory = "https://artifactory.company.org/artifactory/repo"
  if (isSnapshot.value)
    Some(
      "Artifactory Realm" at s"$artifactory-snapshots;build.timestamp=" + new java.util.Date().getTime
    )
  else
    Some("Artifactory Realm" at s"$artifactory-releases;keep_forever=release-artifact")
}

artifact in (Compile, assembly) := {
  val art = (artifact in (Compile, assembly)).value
  art.withClassifier(Some("assembly"))
}

addArtifact(artifact in (Compile, assembly), assembly)

val packAnsible = taskKey[File]("Pack ansible files.")
val ansibleArtifactName = settingKey[String]("Ansible artifact name")

packAnsible := {
  val ansibleZip =
    target.value / s"scala-${scalaBinaryVersion.value}" / s"${name.value}.zip"
  IO.zip(
    IO.listFiles(Path("ansible").asFile).map(f => (f, f.name)),
    ansibleZip,
    None
  )
  ansibleZip
}
artifact in packAnsible := Artifact(name.value, "zip", "zip").withClassifier(Some("ansible"))

addArtifact(artifact in packAnsible, packAnsible)

as you can see I add 2 artifacts to be publish:

  1. uber jar with classifier "assembly"
  2. a zip with some ansible vars with classifier "ansible"

After publishing in my repository I can find almost all what I wish:

  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1-assembly.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1-javadoc.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1-sources.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1.pom
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-SNAPSHOT-ansible.zip
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/maven-metadata.xml

I can see in the maven-metadata all other artifacts except my zip and also the name of the jar does not contain the build.time and therefor will fail on next build unless I give the user the rights to overwrite/delete which I prefer not to.

I tried following the docs and added -Dsbt.override.build.repos=true both in my build server at /usr/local/etc/sbtopts and in the root of my project.

I would like to have all artifact (only my costume is not currently) to be properly published.

Thanks for the help.

1

1 Answers

0
votes

Apparently the issue was in the name I used for my custom artifact:

artifact in packAnsible := Artifact(name.value, "zip", "zip").withClassifier(Some("ansible"))

should be:

artifact in packAnsible := Artifact((Compile / packageBin / artifact).value.name, "zip", "zip")
  .withClassifier(Some("ansible"))

I had a different of . and - in the actual build.