Sbt project depending on a external & private github repository - scala

this tutorial explains clearly how to have a remote github depency dependence in an sbt project using:
lazy val reponame = RootProject(uri("git://github.com/group/reponame.git"))
lazy val root = Project(id = "MLSS", base = file("."), settings = sharedSettings) dependsOn(reponame)
However if the remote repo is private, it doesn't seem to work and throws a
Repository not found.
Cloning into '/Users/.../b6958781f05b85672849/reponame'...
[error] Nonzero exit code (128): git clone git://github.com/group/reponame.git
it seems to be an auth error but how to specify the key?
thanks

For a private repo, you want to use SSH so authentication uses your keys instead of a username & password. The github provided SSH url git#github.com:group/reponame.git isn't a correctly formed URI, but it's equivalent to ssh://git#github.com/group/reponame.git. I just tried a uri dependency on a private repo URL formatted that way and it worked for me. Reference.

just using the https version worked fine to clone the repo (provided you have the key in your sshconfig) but it doesn't add the modules to the classpath:
lazy val pogistan = RootProject(uri("https://github.com/group/reponame.git"))

Related

Create g8 Template From a Git Remote Project

I have a sbt g8 template that I customized for my projects and this is located as one of the sub project in a multi module scala sbt project which is assigned to my organization. For example.,
main-project
- projec1
- sbt-template-project.g8
- some-other-project
The main-project is available in my git repo and I would like to know how I can create a project from the sbt-template-project? I tried the following, but it says "Template Not Found":
sbt new file:https://github.com/my-organization/main-project/tree/master/sbt-template-project.g8
I also tried:
sbt new file:https://github.com/my-organization/main-project/sbt-template-project.g8
I also tried:
sbt new https://github.com/my-organization/main-project/sbt-template-project.g8
What is the correct way to generate the project out of the template?
EDIT: I even tried the following:
sbt new my-organization/main-project -d sbt-template-project-g8
Even that is failing with the message "Template not found"
Your flow is basically not supported - see: http://www.foundweekends.org/giter8/template.html - Giter8 (and sbt new) support only GitHub repositories where the template in either in the root directory or in src/main/g8.
Your best option is to git clone it manually and then call sbt new passing path to the subdirectory:
git clone https://github.com/my-organization/main-project tmp-template-dir
sbt new file://tmp-template-dir/sbt-template-project.g8
rm -rf tmp-template-dir
It is important that the directory name end with .g8.

Sbt/Scala - Gitlab dependency

I'm trying to add in my build.sbt file a dependency to a private gitlab repository via SSH. I have found some documentation online to do this using github examples and I translated this to gitlab:
lazy val libOnGitlab = ProjectRef(uri("git#gitlab.com:username/myproject.git"), "RandomNameHere")
lazy val root = (project in file(".")).dependsOn(libOnGitlab).settings(libraryDependencies += ...)
The problem I have is that Gitlab's SSH link is using a # while github doesn't and this gives me an error:
java.net.URISyntaxException: Illegal character in scheme name at index 3: git#gitlab.com:...
I have already tried many many different things (prepending it with some protocol etc) but I'm pretty new to this and can't manage to solve it. Any ideas?

Pull GitHub repository using Bazel

I need to download an entire GitHub repository using Bazel. Since I'm quite new to this tool I'm not really sure how to achieve that.
My main idea is this:
write a custom repository rule in downloadgithubrepo.bzl (which is located in the project root just like the WORKSPACE file) such as:
def _impl(repository_ctx):
repository_ctx.download("url_to_zipped_github_repo", output='relative_path_to_output_file')
github = repository_rule(
implementation = _impl
and in the WORKSPACE file to write something like this:
load("//:downloadgithubrepo.bzl", "github")
and to invoke a build a BUILD file is needed (also located at the project root)
its contents are the following:
cc_library(
name = "testrun",
srcs = "main.c",
)
I had to add the main.c file otherwise the build is failing - that is one issue and the real issue is that this does not work, as in the build is passing but the GitHub repository is not downloaded.
Am I on the right path at all?? Has anyone done something like this before?
What you're looking might already be implemented in the new_git_repository repository rule, or the git_repository rule if the GitHub project already has Bazel BUILD files wired in.
If the GitHub project does not have BUILD files, a BUILD file is required when using new_git_repository. For example, if you want to depend on a file target (e.g. /foo/bar.txt) or rule target (e.g. a cc_library) in https://github.com/example/repository, and the repository does not have BUILD files, write these lines in your project's WORKSPACE file:
new_git_repository(
name = "example_repository",
remote = "https://github.com/example/repository.git",
build_file_content = """
exports_files(["foo/bar.txt"])
# you can also create targets
cc_library(
name = "remote_cc_library",
srcs = ["..."],
hdrs = ["..."],
)
""",
)
In your BUILD file, reference the external repository's targets using the # prefix:
cc_library(
name = "testrun",
srcs = ["main.c"],
data = ["#example_repository//:foo/bar.txt"],
deps = ["#example_repository//:remote_cc_library"],
)
When you run bazel build //:testrun, Bazel will..
Analyze the dependencies of //:testrun, which include the file main.c and targets from the external repository #example_repository.
Look up the WORKSPACE file for an external repository named example_repository, and finds the new_git_repository declaration.
Perform a git clone on the remote attribute specified in the example_repository declaration.
Write a BUILD file containing the build_file_content string at the project root of the cloned repository.
Analyze the targets #example_repository//:foo/bar.txt and #example_repository//:remote_cc_library
Build the dependencies, and hands them to your //:testrun cc_library.
Build //:testrun.
If the GitHub project does have BUILD files, you do not need to provide an BUILD file. You can refer to the targets directly after specifying the WORKSPACE dependency with git_repository:
git_repository(
name = "example_repository",
remote = "https://github.com/example/repository.git",
)
For more information, check out Bazel's documentation on External Repositories.

sbt not able to connect to private artifactory repository

I'm trying to fetch some dependencies from my private repo, however it seems like sbt is not able to find the credentials. There's also an error in my terminal whenever I try to fetch the dependencies
[error] Unable to find credentials for [Artifactory Realm # artifactory.mydomain.com].
I read a couple of answers already, but none of them are working for me.
What I did so far:
1) I configured my repo
cat ~/.sbt/repositories
[repositories]
local
my-ivy-proxy-releases: https://artifactory.mydomain.com/my-ivy-release-local/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: https://artifactory.mydomain.com/my-ivy-release-local/
2) I created a .credentials file
cat ~/.sbt/.credentials
realm=Artifactory Realm
host=artifactory.mydomain.com
user=myuser
password=mypassword
3) I exported the env variable SBT_CREDENTIALS
export SBT_CREDENTIALS=/Users/myuser/.sbt/.credentials
4) I created credentials.sbt in ~/.sbt/0.13/credentials as well as in ~/.sbt/0.13/plugins/credentials
cat ~/.sbt/0.13/credentials.sbt
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
When I try to access the dependency using curl, everything works just fine.
I read about some alleged solutions already, including:
SBT is unable to find credentials when attempting to download from an Artifactory virtual repo
How to access a secured Nexus with sbt?
How can I provide SBT credentials to my private Artifactory server from a Windows workstation?
I copied credentials.sbt to ~/.sbt/1.0 because i found this answer:
Where should the SBT credentials configuration go? and it looks like it does the trick.

Scala library dependencies in internal artifactory pointing outside

We've got an internal artifactory server and one of my colleagues just put on there the get-coursier library I want to use.
But, when I try to install it through sbt in intellij, the dependencies it needs are trying to be pulled from an external repository, which I can't get to as I'm on an internal only network.
I'm pointing at our internal artifactory using a repositories file in my ~.sbt folder.
How would I define new paths for the dependencies so they would point at out internal artifactory server as well?
Any tips, greatly appreciated.
I add it to the build.sbtlike
val yourRepoRealm = "Artifactory Realm"
val yourRepoUrl = "http://yourhost.com/artifactory/libs-release-local"
Important is that you add this to the settings of the module where you need it:
lazy val sharedSettings: Seq[Def.Setting[_]] = Seq(
...
, resolvers ++= Seq(
yourRepoRealm at yourRepoUrl
, "jitpack" at "https://jitpack.io" // add other repos
), credentials += Credentials(new java.io.File(".credentials"))
, ...
)
This expects that you have your credentials in the project_root/.credentials. like
realm=Artifactory Realm
host=yourHost.com
user=username
password=yourPwd