Store dependencies in private GitHub or Bitbucket repo - scala

We are using sbt 0.13.9 and we want to use a private GitHub repo to store company-wide dependencies.
I try to add a private GitHub repo to the resolvers like this:
resolvers += Resolver.ssh("Company Repo", "git#github.com:company/company-repo.git", "/raw/master")(Resolver.ivyStylePatterns)
// or
resolvers += Resolver.ssh("Company Repo", "git#github.com:company/company-repo.git", "/raw/master")(Resolver.ivyStylePatterns) as("githubuser")
// or
resolvers += Resolver.ssh("Company Repo", "git#github.com:company/company-repo.git", "/raw/master")(Resolver.ivyStylePatterns) as("githubuser", "password")
// or
resolvers += {
val keyFile: File = new File(Path.userHome.absolutePath + "/.ssh/id_rsa")
Resolver.ssh("Company Repo", "git#github.com:company/company-repo.git", "/raw/master")(Resolver.ivyStylePatterns) as("githubuser", keyFile)
}
// or
resolvers += {
val keyFile: File = new File(Path.userHome.absolutePath + "/.ssh/id_rsa")
Resolver.ssh("Company Repo", "git#github.com:company/company-repo.git", "/raw/master")(Resolver.ivyStylePatterns) as("githubuser", keyFile, "keyFilePassword")
}
(For the resolvers where no user and/or no password was supplied a popup appears to enter the username/password.)
However, it is always failing:
[warn] ==== Company Maven Repo: tried
[warn] com.company/my-module_2.11/2.0.0/ivys/ivy.xml
The location of the files inside the repo are correct, I am 100% sure.
Can sbt handle git repos as resolvers at all? Did someone has a working example with a private GitHub repo? Bitbucket would be fine too.
Again, the repo is private and the repos is a git repo, not http(s) nor sftp.
Oh, and yes, I know bintray, but right now we don't want to pay 45 USD monthly to manage like 3 dependencies for 2 devs.
PS: My configuration is based on examples from
https://groups.google.com/forum/#!topic/maven-and-scala/dhzEZ0dR_is and
SBT doesn't use ssh-based resolver to resolve dependency

Related

Unable to resolve snapshot dependency from Nexus Repository Manager sbt

The sbt can't download dependency from nexus repository manager.
Here is the resolver for repo in build.sbt file:
resolvers += "Sonatype Nexus Repository Manager" at "nexus repo url"
Resolver is working fine in case of release version eg 1.0.0 but not for snapshot version like 1.0.0-SNAPSHOT.
Below is the dependency that added in build.sbt
"artifacts" % "name" % "1.0.0-SNAPSHOT" changing()

Sbt - Specify dependency extension

i have troubles with Sbt.
In my local instance of JFrog Artifactory i have published a java library without the .pom file, so i have just the .jar file.
Configuration:
//build.sbt
libraryDependencies += "com.example" % "my-library" % "1.0" % "provided"
//build.properties
sbt.version = 1.3.0-RC2
Obliviously i have configured the resolvers properly.
Sbt fails with the following error:
not found: http://[Artifactory]/artifactory/maven/com/example/my-library/1.0/my-library-1.0.pom
The error is clear, indeed .pom file doesn't exists.
There is a way to specify, for a specific dependency, the extension ?
If for whatever reason you published the jar without a pom file on purpose, you can specify an explicit URL for the jar you want to depend on, e.g.
libraryDependencies += "slinky" % "slinky" % "2.1"
from "https://slinky2.googlecode.com/svn/artifacts/2.1/slinky.jar"
But if you just published the library ivy-style (so an ivy.xml file was published instead of a pom file), you just need to specify a right resolver for your repository, which will have ivy-style patterns.
When publishMavenStyle is true, a POM is generated by the makePom action and published to the repository.
Add this line in your build.sbt
publishMavenStyle := true
Configuring Artifact Resolution
To resolve artifacts through Artifactory, simply add the following code snippet to your build.sbt file:
resolvers += "Artifactory" at "http://<host>:<port>/artifactory/<repo-key>/"
Deploying Artifacts
To deploy sbt build artifacts to repositories in Artifactory, add the following code snippets to your build.sbt file.
For releases, add:
publishTo := Some("Artifactory Realm" at "http://<host>:<port>/artifactory/<repo-key>")
credentials += Credentials("Artifactory Realm", "<host>", "<USERNAME>", "<PASS>")
For snapshots, add:
publishTo := Some("Artifactory Realm" at "http://<host>:<port>/artifactory/<repo-key>;build.timestamp=" + new java.util.Date().getTime)
credentials += Credentials("Artifactory Realm", "<host>", "<USERNAME>", "<PASS>")
Where host and port are the host URL and port on which Artifactory is running, and repo-key is the Artifactory repository to which you are deploying artifacts.

SBT publish: Repository for publishing is not specified

I am trying to publish artifact with SBT to remote Nexus repository with command sbt publish.
My build.sbt:
credentials += Credentials("Sonatype Nexus", "nexus.local", "username", "password")
publishTo := Some("Sonatype Nexus" at "http://nexus.local:8080/repository/releases")
But I get an error:
Repository for publishing is not specified
I successfully push to this repository with Maven. Could you help please?

Play dependencies on a scala project

I am trying to get a play project to have another local scala project as a dependency. I have the local scala project deploying to my local M2 repository with this line in my configuration file.
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
And I am trying to load the dependency in my play project with this line
val appDependencies = Seq(
"com.experimentalcork" %% "timeywimeyentities" % "0.0.2"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",testOptions in Test := Nil
)
In the logs as I do a 'play compile' it states that it can not find the dependency. It is looking in the place where I specified the dependency would be.
[warn] ==== Local Maven Repository: tried
[warn] file://C:/Users/caelrin/.m2/repository/com/experimentalcork/timeywimeyentities_2.9.1/0.0.2/timeywimeyentities_2.9.1-0.0.2.pom
And when I go to check that directory, I can confirm that the pom and jar files are there. I am completely baffled as to how it could look in the directory that contains the pom and not find it. Has anyone had any experiences with this?
You need a .dependsOn call too, I think.
val timeywimeyentities: Project = Project([Put all of your settings here for the project just like you would a play project])
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",testOptions in Test := Nil
).dependsOn(timeywimeyentities % "compile->compile")
Adding "compile->compile" makes the main code of your play project rely on the main code of your dependency. If you wanted to make the test code of your play project also depend on it, you could use "compile->test". If you want only the test code of both to see each other, you could use "test->test". You can also chain them together, for example: "compile->compile;test->test". If all you want is "compile->compile", you need not explicitly state it.
See https://github.com/harrah/xsbt/wiki/Getting-Started-Multi-Project for more information.

Play framework and sbt: passing credentials to a nexus passowrd protected repo

I need to define as a dependency the following library:
url: http://deploy.cloud.testmx.com:8081/nexus/content/groups/public/
user: testmx
pass: testmx#testmx
groupId: testmx
artifactId: testmxcommons
version: 1.0.0-SNAPSHOT
So I defined the following project/Build.scala
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "testmxproject"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"mysql" % "mysql-connector-java" % "5.1.18",
"testmx" % "testmxcommons" % "1.0.0-SNAPSHOT"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
credentials += ("testmx public", "deploy.cloud.testmx.com:8081", "testmx", "testmx#testmx"),
resolvers += "testmx public" at "http://deploy.cloud.testmx.com:8081/nexus/content/groups/public/"
)
}
and I get the following error:
[warn] module not found: testmx#testmxcommons;1.0.0-SNAPSHOT
[warn] ==== testmx public: tried
[warn] http://deploy.cloud.testmx.com:8081/nexus/content/groups/public/testmx/textmxcommons/1.0.0-SNAPSHOT/textmxcommons-1.0.0-SNAPSHOT.pom
I tried several alternatives but they give me the same error...
I've checked this article and this SO question
And also tried saving the user and password on an external file, as it's explained here and here.
any idea?
-- edit to clarify --
I changed the real url because it's not a public repo I'm working with... The real url is there and the pom that sbt is trying to find does exist...
ps: BTW.. where are sbt scaladocs???
You need to tell SBT what repository you want to publish to:
publishTo := Some("testmx public" at "http://deploy.cloud.testmx.com:8081/nexus")
Additionally if you don't want to keep your credentials in the Build file, you can tell it to retrieve them locally by adding the line:
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
And in your ~/.ivy2 directory create a .credentials file like this:
realm=Sonatype Nexus Repository Manager
host=deploy.cloud.testmx.com
user=testmx
password=testmx#testmx
See https://github.com/harrah/xsbt/wiki/Publishing for more
There were two problems when passing the credentials.
The first was that I was passing the wrong Realm. (Thanks to Alex Varju for this one)
You have to pass the same Realm that the server is sending you when trying to log (Just press ctrl-shift-I or F12 on chromium and got to network to have a look at it)
The second problem is that I was passing the port number, and sbt doesn't seem to like that...
So, in the end I did it like this and it works ok:
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
credentials += ("Sonatype Nexus Repository Manager", "deploy.cloud.testmx.com", "testmx", "testmx#testmx"),
resolvers += "testmx public" at "http://deploy.cloud.testmx.com:8081/nexus/content/groups/public/"
)
Settings your credentials in a different file, as expected, worked ok too with the same modifications...
Thanks to all for your answers