scalamavensbtsbt-pluginsbt-revolver

Add a maven dependency to SBT project


I am trying to reference a maven project dependency in my build.sbt file. I understand I need to add an additional resolver to my file since the project is hosted in an internal artifactory store

build.sbt

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "2.4.4",
  "org.apache.spark" %% "spark-sql" % "2.4.4",
  "com.<companyname>" %% "<libraryname>" % "2.3.0"
)

resolvers += "<library name>" at "http://artifactory.<internal url>.io:80/dsc-mvn"

However, it turns out that SBT ends up searching for a path that has _2.11 version appended to it. This is the error message that I see in IntelliJ

[info] Loading settings for project sbt-demo from build.sbt ...
[warn] Discarding 1 session setting.  Use 'session save' to persist session settings.
[info] Set current project to SparkExample (in build file:<project_path>)
[info] Defining Global / sbtStructureOptions
[info] The new value will be used by Global / ssOptions
[info] Reapplying settings...
[info] Set current project to SparkExample (in build file:<project_path>)
[info] Updating ...
[warn]  module not found: com.<companyname>#<libraryname>_2.11;2.3.0
[warn] ==== local: tried
[warn]   /Users/vshah/.ivy2/local/com.<companyname>/<libraryname>_2.11/2.3.0/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /Users/vshah/.sbt/preloaded/com.<companyname>/<libraryname>_2.11/2.3.0/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////Users/vshah/.sbt/preloaded/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom
[warn] ==== <libraryname>: tried
[warn]   http://artifactory.<internal url>.io:80/dsc-mvn/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.<companyname>#<libraryname>_2.11;2.3.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]

Invalid Path (as the project is trying to search above)- http://artifactory.<internal url>.io/dsc-mvn/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom

Valid path - http://artifactory.<internal url>.io/dsc-mvn/com/<companyname>/<libraryname>/2.3.0/<libraryname>_2.11-2.3.0.pom

My question is how do I let SBT know that I am referencing a maven project at the above mentioned valid path?


Solution

  • This should work:

    "com.<companyname>" % "<libraryname>" % "2.3.0"
    

    The %% in the definition automatically appends the project scala version to the library name. Check out the official sbt documentation for more info.