sbt can't find local repository defined by Resolver.file() - scala

I use
name := "sbt-publish-test"
version := "0.1-SNAPSHOT"
publishTo := Some(Resolver.file("sbt-repo", file("/home/pishen/sbt-repo")))
and sbt publish to publish my project into the directory.
Now in another project, I want to resolve the project I just published. I use
resolvers += "my-repo" at "file:///home/pishen/sbt-repo"
libraryDependencies += "default" %% "sbt-publish-test" % "0.1-SNAPSHOT"
and is able to resolve the project without any error. The result of show resolvers is:
> show resolvers
[info] List(my-repo: file:///home/pishen/sbt-repo)
But, when I use
resolvers += Resolver.file("my-repo", file("/home/pishen/sbt-repo"))
libraryDependencies += "default" %% "sbt-publish-test" % "0.1-SNAPSHOT"
The result of show resolvers become:
> show resolvers
[info] List(FileRepository(my-repo,FileConfiguration(true,None),Patterns(ivyPatterns=List(), artifactPatterns=List(/home/pishen/sbt-repo/[organisation]/[module](_[scalaVersion])(_[sbtVersion])/[revision]/[artifact]-[revision](-[classifier]).[ext]), isMavenCompatible=true, descriptorOptional=false, skipConsistencyCheck=false)))
and sbt said that it can't resolve the dependency when I typed sbt update:
[warn] module not found: default#sbt-publish-test_2.10;0.1-SNAPSHOT
[warn] ==== local: tried
[warn] /home/pishen/.ivy2/local/default/sbt-publish-test_2.10/0.1-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/default/sbt-publish-test_2.10/0.1-SNAPSHOT/sbt-publish-test_2.10-0.1-SNAPSHOT.pom
[warn] ==== my-repo: tried
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: default#sbt-publish-test_2.10;0.1-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Is this a bug? Or am I use Resolver.file() in a wrong way? What's the difference between "name" at "url" and Resolver.file()? I'm using sbt 0.13.7.

My suspicion is that when you use Resolver.file in that context, it's intended to be more of a "builder" creator, expecting subsequent method calls to fill in additional configuration information that have different defaults when using the "name" at "uri" syntax.
The sbt ScalaDoc for Resolver.file.apply alludes to something along these lines:
Constructs a file resolver with the given name. The patterns to use must be explicitly specified using the ivys or artifacts methods on the constructed resolver object.
When I've done something similar to what you're doing, I start with a File and use its API to convert it into the URI form:
resolvers += "my-repo" at file("/home/pishen/sbt-repo").toURI.toASCIIString

Related

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?
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.
refer to https://mvnrepository.com/artifact/org.scala-sbt to get the right Build tool for your project, and kindly check if the version in the dependency matches the version of your scala .
Can you please tell me more about the kind of dependency you need?

sbt unresolved library dependencies

sbt compile issues unresolved dependencies error
Research SBT configuration. I do have the correct syntax. But SBT still issues error
name := "MyProject"
version := "1.0"
scalaVersion := "2.11.12"
resolvers +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases"
libraryDependencies += "java.io.IOException" % "IOException" % "latest.integration"
libraryDependencies += "java.io.FileReader" % "FileReader" % "latest.integration"
libraryDependencies += "java.io.FileNotFoundExceptiom" % "FileNotFoundException" % "latest.integration"
I have a working scala program. I expect the dependencies to be included instead I receive the following Warning. What am I missing?
Warning Message
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: java.io.IOException#IOException;latest.integration: not found
[warn] :: java.io.FileReader#FileReader;latest.integration: not found
[warn] :: java.io.FileNotFoundExceptiom#FileNotFoundException;latest.integration: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
hmm, there's something weird.
Typically you declare dependencies in a form of a lib/jar that does contain a set of classes, and not the individual class itself.
In your specific case, you don't even need to add any dependency to get java.io.* classes since it belong to standard library and are included by default

Why is ScalaTest 3.0.1 for 2.12 not resolved?

I have a scala project that is cross built for 2.11 and 2.12
crossScalaVersions := Seq("2.11.8", "2.12.0")
I've added dependency for scalatest.
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"org.mockito" % "mockito-all" % "1.10.19" % "test"
)
resolvers ++= Seq(
"Akka" at "http://akka.io/repository/",
"Sonatype" at "http://oss.sonatype.org/content/repositories/releases"
)
I can see that 2.12 version is published for scalatest from 3.0.0. SBT is not able to resolve it though.
[warn] ==== sbt-releases-repo: tried
[warn] http://repo.typesafe.com/typesafe/ivy-releases/org.scalatest/scalatest_2.12/3.0.1/ivys/ivy.xml
[warn] ==== sbt-plugins-repo: tried
[warn] http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.scalatest/scalatest_2.12/3.0.1/ivys/ivy.xml
[warn] ==== my-ivy-proxy-releases: tried
[warn] http://artifactory.internal.com/ivy-releases/org.scalatest/scalatest_2.12/3.0.1/ivys/ivy.xml
[warn] ==== my-maven-proxy-releases: tried
[warn] http://artifactory.internal.com/maven-releases/org/scalatest/scalatest_2.12/3.0.1/scalatest_2.12-3.0.1.pom [warn] ==== Akka: tried
[warn] http://akka.io/repository/org/scalatest/scalatest_2.12/3.0.1/scalatest_2.12-3.0.1.pom
[warn] ==== Sonatype: tried
[warn] http://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_2.12/3.0.1/scalatest_2.12-3.0.1.pom [info] Resolving jline#jline;2.14.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scalatest#scalatest_2.12;3.0.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Any pointers to what is missing here?
UPDATE:
Adding my ~/.sbt/repositories setting
[repositories]
local
my-ivy-proxy-releases: http://artifactory.internal.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://artifactory.internal.com/maven-releases/
According to your log, SBT doesn't search for the dependency on Maven Central, which is the most straightforward place to get Scalatest from. This is not an issue with a default SBT config (since Maven Central is one of the default resolvers); but here, you have a specific SBT config, to use your organization's internal repos instead (on http://artifactory.internal.com).
You need to either add Maven Central in your SBT resolvers (but that's probably not what you want, in the long term) or check with your Artifactory admins if the artifactory.internal.com/maven-releases repo is the one that's supposed to proxy Maven Central dependencies, and if it's properly configured. I think they should also be able to export from Artifactory a Maven configuration file pointing to the repos you need to use: you could then just copy and paste the URLs from that to your SBT config file.

Why is sbt-scapegoat trying to resolve version 1.0.0?

I'm trying to use sbt-scapegoat by adding this to plugins.sbt:
addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.0.4")
Then in by build.scala file I'm doing this:
import com.sksamuel.scapegoat.sbt.ScapegoatSbtPlugin.autoImport._
scapegoatVersion := "1.1.0"
This is what's shown on the sbt-scapegoat github site. I fire up sbt and let it resolve sbt-scapegoat 1.0.4, which it does. So far so good. Then if I run scapegoat I get:
[info] Resolving com.sksamuel.scapegoat#scalac-scapegoat-plugin_2.10;1.0.0 ...
[warn] Host repo1.maven.org not found. url=https://repo1.maven.org/maven2/com/sksamuel/scapegoat/scalac-scapegoat-plugin_2.10/1.0.0/scalac-scapegoat-plugin_2.10-1.0.0.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn] module not found: com.sksamuel.scapegoat#scalac-scapegoat-plugin_2.10;1.0.0
[warn] ==== local: tried
[warn] /Users/wmy965/.ivy2/local/com.sksamuel.scapegoat/scalac-scapegoat-plugin_2.10/1.0.0/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/com/sksamuel/scapegoat/scalac-scapegoat-plugin_2.10/1.0.0/scalac-scapegoat-plugin_2.10-1.0.0.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.sksamuel.scapegoat#scalac-scapegoat-plugin_2.10;1.0.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Where is 1.0.0 dependency coming from? My project is scala 2.11.7 and I'm using sbt 0.13.11. I don't see any mention of another resolver on the sbt-scapegoat web site.
In my output, my console shows a bunch of found analysis errors but the generated HTML doc is basically empty--doesn't show the errors displayed on the console.
How can I fix this?
To set scapegoatVersion for subprojects, you need to either put it in common settings as described here, or use scapegoatVersion in ThisBuild := "1.1.0". To avoid the error, I think setting scalaVersion in the root project would work:
lazy val root = (project in file(".")).
aggregate(dotdash, dotdash_messages).
settings(
scalaVersion := "2.11.7"
)
or again use scalaVersion in ThisBuild.
I also suggest raising an issue at https://github.com/sksamuel/sbt-scapegoat.
In addition to the above answer from Alexey, Just to answer WHERE, you may want to check ScapegoatPlugin.scala.
This is an sbt Auto Plugin and the method buildSettings have overridden the scapegoatVersion to be used.
override def buildSettings = super.buildSettings ++ Seq(
scapegoatVersion := "1.0.0",
scapegoatRunAlways := true,
scapegoatConsoleOutput := true,
scapegoatVerbose := true,...
We can specify the version we choose to use, scapegoatVersion in ThisBuild.
For me nothing from above works, so potentially there are two problems and mine has been resolved by using fixed version of plugin
addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.0.9")

sbt and scct .... module not found: reaktor#sbt-scct;0.2-SNAPSHOT

scala is version 2.10.2 and sbt is 0.13.0
I am trying to setup scct for scala unit test code coverage so in build.sbt
I added
seq(ScctPlugin.instrumentSettings : _*)
and in project/plugins.sbt I added
resolvers += Classpaths.typesafeResolver
resolvers += "scct-github-repository" at "http://mtkopone.github.com/scct/maven-repo"
addSbtPlugin("reaktor" %% "sbt-scct" % "0.2-SNAPSHOT")
I get errors like ....
module not found: reaktor#sbt-scct;0.2-SNAPSHOT
Last message is
[warn] ==== scct-github-repository: tried
[warn] http://mtkopone.github.com/scct/maven-repo/reaktor/sbt-scct_2.10_0.13/0.2-SNAPSHOT/sbt-scct-0.2-SNAPSHOT.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: reaktor#sbt-scct;0.2-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] reaktor:sbt-scct:0.2-SNAPSHOT (sbtVersion=0.13, scalaVersion=2.10)
I look in http://mtkopone.github.io/scct/maven-repo/reaktor/
and I see the one I seem to need is missing e.g. I see
sbt-scct_2.9.2_0.13/
scct_2.10/
and a bunch of others but no ... sbt-scct_2.10_0.13
Can you help ? (I am a sbt newbie)
SCCT has a new source code repository: https://github.com/SCCT/scct
As a result you can fetch a release version from maven central with addSbtPlugin("com.github.scct" %% "sbt-scct" % "0.2") in your plugins.sbt file.
My project to reproduce is on GitHub.
Update:
The repository has been relocated at https://github.com/sqality/scct
and you need addSbtPlugin("com.sqality.scct" % "sbt-scct" % "version") in your plugins.sbt file.
The original SCCT is inactive now.
Here are the two most active forks.
http://github.com/sqality
http://github.com/scoverage