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.
Related
I signed up for the Github private npm registry beta and followed their instruction: https://github.com/features/package-registry
Works great with npm but I'd prefer using yarn. And while npm has no issues finding the registered package, yarn can't find it at all.
yarn add #omniphx/adminite-adminite-ui-components outputs:
yarn add v1.19.0
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍 Resolving packages...
error Couldn't find package "#omniphx/adminite-ui-components" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
After reading up on private repos with yarn, I thought the trick was due to yarn having a slightly different rc format. Unfortunately, that didn't work either and yarn is still unable to find the private registry.
.npmrc
registry=https://registry.npmjs.org
#omniphx:registry=https://npm.pkg.github.com/omniphx
.yarnrc
registry "https://registry.npmjs.org"
"#omniphx:registry" "https://npm.pkg.github.com/omniphx"
Also confirmed that my github token is set too with yarn config list:
yarn config v1.19.0
info yarn config
{
'version-tag-prefix': 'v',
'version-git-tag': true,
'version-commit-hooks': true,
'version-git-sign': false,
'version-git-message': 'v%s',
'init-version': '1.0.0',
'init-license': 'MIT',
'save-prefix': '^',
'bin-links': true,
'ignore-scripts': false,
'ignore-optional': false,
registry: 'https://registry.npmjs.org',
'strict-ssl': true,
'user-agent': 'yarn/1.19.0 npm/? node/v12.11.1 darwin x64',
email: 'mattjmitchener#gmail.com',
lastUpdateCheck: 1570679687836,
username: 'omniphx',
'#omniphx:registry': 'https://npm.pkg.github.com/omniphx'
}
info npm config
{
'//npm.pkg.github.com/:_authToken': 'fake12345',
registry: 'https://registry.npmjs.org',
'#omniphx:registry': 'https://npm.pkg.github.com/omniphx',
python: '/usr/bin/python'
}
Any idea?
Resolved
Changed "#myorg:registry" "https://npm.pkg.github.com/myorg"
To "#myorg:registry" "https://npm.pkg.github.com"
I've just run into a similar situation. It seemed that yarn was only looking in the main Yarn package registry for my organization's private package. I had copied the examples from GitHub's Packages documentation for constructing your .npmrc file directly to the .yarnrc file in the project that will be consuming the app, not knowing that the formats were different (I've never had to deal with .yarnrc files before).
However, after updating the .yarnrc file with the correct format that you've mentioned above (which I also found in googling around), yarn successfully found the private package and installed it correctly.
As a heads up, my yarn version: 1.17.3
Steps I Took
Start new terminal session
cd to the project
nvm use (if you have a specific node version to use)
Add the correctly-formatted .yarnrc file to the project. See below for what it looks like.
Manually add the package and version range to the package.json for my private package
Run npm login --registry=https://npm.pkg.github.com --scope=#MyOrg
See the note below on scope / org gotcha's
Run yarn
That worked for me.
.yarnrc
"#myorg:registry" "https://npm.pkg.github.com"
Note: See below for a note on the org / scope name gotcha's
Other Notes
I know that it appears that you don't have any issues with this, given your GH username / scope above, but for anyone else that comes here, the documentation on GH is a little sparse with regards to mapping your username / org name to a scope in the package name. Just remember these little gotcha's here:
The name of your package must always be scoped to your org (or username)
E.g., name: #johndturn/my-package
If your organization has capital letters in it, like MyOrg, just replace them in the name of the package in your package.json and your .yarnrc with lowercase
E.g., name: #myorg/my-package
Note: When authenticating with npm login, I still have kept the uppercase letters in the --scope= argument.
The name of your package doesn't have to be the same name of the repo.
E.g., for a repo called MyOrg/random-prefix.js-lib, you can have name: #myorg/js-lib in your package.json file for the project itself. Then, installing it in other projects will look something like #myorg/js-lib: 1.0.0.
The problem I had is slightly different.
After tried what John suggested I still can't add private registry packages with yarn (but perfectly fine with npm)
Then I realise two things:
For GitHub packages, npm is fine with either
registry=https://npm.pkg.github.com/my-org
or
#my-org:registry=https://npm.pkg.github.com
but yarn only allow the latter syntax.
Docs from Github website only show the first syntax which could cause problems for yarn users.
Another thing is that if you npm login to the private registry but use a .yarnrc file in your project, yarn can't really mix your npm credentials with it. Although it seems behave differently on different environment.
But it would seems to be a best practice to stick with either yarn login + .yarnrc, or npm login + .npmrc (you can still use yarn to manage your packages in both cases)
In Yarn v2+ the setup has changed quite a bit. ".yarnrc" is ignored and only ".yarnrc.yml" is used.
To setup a private registry with a scope and token from env, add something along these lines to the ".yarnrc.yml" file (fontawesome example):
npmScopes:
fortawesome:
npmRegistryServer: "https://npm.fontawesome.com"
npmAuthToken: ${FONTAWESOME_TOKEN}
Documentation: https://yarnpkg.com/configuration/yarnrc#npmScopes
I'm not an expert with npm/yarn so I might be misunderstanding what is happening here, but I don't think package proxying from the npm registry works with yarn yet. Could that be related? When package proxying was released for npm I remember reading comments on Twitter from people that tried it with yarn and it didn't work.
Found the Twitter thread here:
https://twitter.com/github/status/1171832034580451328
It doesn't work with Yarn. As soon as I change the registry url -> Couldn't find package.
I issue the sbt publish command, and get a prompt asking me to enter a username and a password. Can I provide them in build.sbt or some place else, so I don't have to manually enter them?
In my build.sbt file I have this:
publishTo := Some(Resolver.sftp("Server", "url", "port"))
You can put credentials in a file and reference in credentials.sbt so that sbt will load it, and use it while publishing or dependency download,
STEP1: setup creds file path in ~/.sbt/1.0/plugins/credentials.sbt
echo 'credentials += Credentials(Path.userHome / ".sbt" / ".credentials")' > ~/.sbt/1.0/plugins/credentials.sbt
note: echo some-stuff > some-file will redirect contents to a file. echo is a linux command
STEP2: Your ~/.sbt/.credentials would look like,
realm=Artifactory Realm // or Sonatype Nexus Repository Manager
host=server.com // don't put in http:// or https:// protocal
user=your.username.for.server.com
password=password.for.server.com
STEP3: setup publish config in build.sbt something like below:
publishTo in ThisBuild := {
if (isSnapshot.value)
Some("Artifactory Realm" at "server.com" + "/artifactory/libs-snapshot-local")
else
Some("Artifactory Realm" at "server.com" + "/artifactory/libs-release-local")
}
STEP4: you can verify credentials.sbt is picked up by sbt, just by running sbt clean compile
$ sbt clean compile
[info] Loading settings for project global-plugins from idea.sbt,credentials.sbt ...
Related resources:
Official documentation: https://www.scala-sbt.org/1.0/docs/Publishing.html
How to access a secured Nexus with sbt?
SBT publish to JFrog artifactory
Look in the logs closely for any location where sbt might be looking for the credentials file. Ex: Unable to find credentials file /root.ivy2/.credentials.
Notice that root and ivy2 are separated by a dot and not a slash. Create the above directory if it does not exist and place the credentials as shown above in the .credentials file probably using cat if the OS is linux or macos.
sbt version : 0.13
When I package the scala project using "sbt package", an error occur to me ,like this:
Server access Error: Connection timed out: connect url=https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-git/scala_2.10/sbt_0.13/0.8.5/ivys/ivy.xml
and I input path
https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-git/scala_2.10/sbt_0.13/0.8.5/ivys
into browser I use which browse sites through proxy, it will redirect to
https://dl.bintray.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-git/scala_2.10/sbt_0.13/0.8.5/ivys
I find the following path exists:
https://dl.bintray.com/typesafe/ivy-releases/com.typesafe.sbt/"
but
sbt-git/scala_2.10/sbt_0.13/0.8.5/
Doesn't the project is "marathon" which is written in Scala, the site is "https://github.com/mesosphere/marathon". I download the project, then switch into the root directory of "marathon",and using "sbt package" commder. Are there some problem in repositories?
I want to add some fast local maven repository url to sbt, say:
http://maven.example.com/public
I want to add it to "global", so that I don't need to add them to each of sbt project. And also want to be tried first when sbt downloading some jars.
But I can't find useful information to do this, how to do it?
(My sbt version is 0.13.1)
With the help of a friend, finally I found the solution:
create a new file ~/.sbt/repositories
add content like this:
[repositories]
local
my-maven-repo: http://example.org/repo
my-ivy-repo: http://example.org/ivy-repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
See official doc: http://www.scala-sbt.org/0.13.2/docs/Detailed-Topics/Library-Management.html#override-all-resolvers-for-all-builds
Modify your global configuration file, which is normally located in ~/.sbt/0.13/global.sbt, if it's not there you can create it.
In the file add following line:
externalResolvers := { ("Fast Repo" at "http://maven.example.com/public") +: externalResolvers.value }
You can confirm it's working by executing show externalResolvers in any project to see the list of resolvers. Your newly added resolver should be first.
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"))