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.
sbt resolver is the configuration for repository that contains jars and their dependencies. for example the below is a resolver definition for a repository called Sonatype and it points at snapshot releases (dev versions) resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
To use publishing, you need to specify the repository to publish to and the credentials to use. Once these are set up, you can run publish . The publishLocal action is used to publish your project to your Ivy local file repository, which is usually located at $HOME/. ivy2/local/ .
If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.
All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.
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
orartifacts
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With