I would like to access a Bintray repository with credentials from sbt. I have tried the following:
resolvers += Resolver.bintrayRepo("...", "...")
as well as,
resolvers += Resolver.url("...", url("..."))(Resolver.ivyStylePatterns)
followed by
credentials += Credentials(Path.userHome / ".bintray" / ".credentials")
The problem arises when I try to add a library dependency from the Bintray Repository. It gives me an unresolved dependency error.
Does anyone know if there is a specific way to add library dependencies when accessing a bintray repository via sbt?
There are different credentials for publishing vs. resolving.
I have published & resolved Maven artifacts with these settings:
In project/maven.sbt:
addMavenResolverPlugin
In build.sbt:
publishMavenStyle := true
Either in build.sbt or ~/.sbt/0.13/credentials.sbt:
// publish to bintray
credentials += Credentials("Bintray API Realm", "api.bintray.com", "<user>", "<bintray API key>")
// resolve from bintray
credentials += Credentials("Bintray", "dl.bintray.com", "<user>", "<bintray API key>")
To publish with sbt publish, add this to build.sbt:
publishTo := Some("<label>" at s"https://api.bintray.com/content/<user>/<organization>/<package>/${version.value}")
Remember that this only uploads the files to bintray.
Only you can resolve these files as long as you provide the credentials as shown above.
To resolve uploaded files (published or not), add this to build.sbt:
resolvers += Resolver.bintrayRepo("<user>", "<organization>")
On Bintray, you have a time limit to decide whether to discard or publish uploaded package version files.
Resolver credentials are necessary under several conditions:
- the uploaded package version files have not yet been published
- the uploaded package version files have been published to a private repo
Resolver credentials are not necessary for published uploaded package version files.
Related
I'm trying to publish some scala code to an artifactory repo, and I want to customize the jarname for the publish target.
When I modify the assembly/assemblyJarName it works when I run sbt assembly but as soon as I run sbt publish the jarname in artifactory doesn't match what I defined.
Why does sbt not use the defined jarname when publishing?
I changed the jarname in assembly/assemblyJarName and I expected the version I put in that value to be uploaded to artifactory.
The jar that ends up in artifactory looks like this: <package_name>_<scala_version>-<package_version>---assembly.jar
I can't figure out how to update the string that's uploaded to artifactory.
When I look at the logs from the CI system I see a message like this:
published pcakage_name_scala_version to https://artifactory.domain.com/artifactory/libs-snapshot-local;build.number=11;build.timestamp=1668632283151/com/org/package_name_scala_version/version_number-SNAPSHOT/package_name_scalaversion-version_number-SNAPSHOT-assembly.jar
So the file that's "uploaded" in the logs doesn't even match that artifat that's in artifactory.
There's some magic happening and it's not clear what
I pulled down the sources and build/published it locally. I want to debug into sources jars. When I publish it locally, I clearly see it also publishes source jars.
[info] published securesocial-testkit_2.10 to local\ws.securesocial\securesocial-testkit_2.10\master-SNAPSHOT\srcs\securesocial-testkit_2.10-sources.jar
I don't know how to reference this jar.
Changing "ws.securesocial" %% "securesocial" % "master-SNAPSHOT" to "ws.securesocial" %% "securesocial" % "master-SNAPSHOT-sources" doesn't work.
Add withSources() to the dependency definition.
From Download Sources in the official documentation of sbt:
Downloading source and API documentation jars is usually handled by an
IDE plugin. These plugins use the updateClassifiers and
updateSbtClassifiers tasks, which produce an Update Report referencing
these jars.
To have sbt download the dependency's sources without using an IDE
plugin, add withSources() to the dependency definition. For API jars,
add withJavadoc(). For example:
libraryDependencies += "org.apache.felix" % "org.apache.felix.framework" % "1.8.0" withSources() withJavadoc()
Note that this is not transitive. Use the update-*classifiers tasks
for that.
You can also run sbt update-classifiers to download sources and javadoc jars for all project dependencies at once
For sbt 1.0, command is sbt updateClassifiers
For me, it worked better with
sbt ';reload plugins; updateClassifiers'
I forked a Scala library from GitHub, and I want to import it to another project.
How can I tell sbt where to find this package?
For example, I'm writing a program in ~/code/scala/myProgram, and I want to import a library from ~/code/scala/otherlib.
If it is supported by the project you have cloned (that is, if it supports SBT and is configured to publish to a repository), you can publish it locally with the sbt command sbt publish-local. For example:
cd ~/code/scala/otherlib
sbt publish-local
This will build and publish this library in your local Ivy repository (typically ~/.ivy2/local). Note that you will need to repeat this each time you modify the otherlib sources.
After the project's published locally to the local Ivy repository, you can specify otherlib as a dependency in your SBT project, using the regular SBT dependency for the original version of the forked library (assuming that you haven't changed its ID, version, group ID, etc.). For example, by adding:
libraryDependencies += "com.some_company" % "otherlib" % "1.0.0"
to your build.sbt file.
Now, when you build your project, it will find otherlib in your local Ivy repository (as if it'd been pulled down from a regular repository) and will use your custom version of it.
If otherlib doesn't support SBT, or isn't configured to publish to a repository, and you do not want to modify it to do so, then you can simply copy its .jar file(s) to the /lib directory (~/code/scala/myProgram/lib) of your project.
SBT supports git repositories out of the box. The support is for clone and checkout. See my answer to Can SBT refresh git uri dependency (always or on demand)? or Using Git local repository as dependency in SBT project?, that boil down to the following in build.sbt:
lazy val gitRepo = "git:file:///Users/jacek/sandbox/so/sbt-git/git-repo/#master"
lazy val g = RootProject(uri(gitRepo))
lazy val root = project in file(".") dependsOn g
Once you define the dependency (between projects) you can use it - the git-hosted project - with no other configuration.
How will I download all the robolectric dependent jars, to avoid runtime downloading and make it offline? I need to use Robolectric.buildActivity(), which is part of 2.x.x versions.
any idea on this ?
Starting with Robolectric 2.4 they added two system properties to allow you to tell the Robolectric test runner to use local copies of the dependencies. See the Configuring Robolectric page.
The settings are:
robolectric.offline - Set to true to disable runtime fetching of jars
robolectric.dependency.dir - When in offline mode, specifies a folder containing runtime dependencies
One way to figure out which files you need to copy to the dependencyDir, is to run gradlew testDebug -i (or maybe with -d) and watch the output to see which jars are being downloaded at runtime. Then copy them to a known location on your build machine. (Another way to see which files you need, is to look at SdkConfig.java and get the dependency jars mentioned there along with their dependencies.)
For the current Robolectric 3.0-rc2, these are the files it needs:
accessibility-test-framework-1.0.jar
android-all-5.0.0_r2-robolectric-1.jar
icu4j-53.1.jar
json-20080701.jar
robolectric-annotations-3.0-rc2.jar
robolectric-resources-3.0-rc2.jar
robolectric-utils-3.0-rc2.jar
shadows-core-3.0-rc2.jar
sqlite4java-0.282.jar
tagsoup-1.2.jar
vtd-xml-2.11.jar
Copy these files to a known location, like say /home/jenkins/robolectric-files/, and then edit your build.gradle with something like this:
afterEvaluate {
project.tasks.withType(Test) {
systemProperties.put('robolectric.offline', 'true')
systemProperties.put('robolectric.dependency.dir', '/home/jenkins/robolectric-files/')
}
}
Here is how I solved it for org.robolectric:robolectric:3.0
https://gist.github.com/kotucz/60ae91767dc71ab7b444
I downloads the runtime dependencies into the build folder and configures the tests to use it - see setting the system properties.
I had this issue too, and found the cause to be the org.robolectric.Testrunner creating a org.robolectric.MavenCentral object, which declares a Maven repository using an Internet-url (Robolectric 2.3-release). Offline builds will not be able to access that url.
In my case I'm required to use a Maven repository proxy, so I replaced the url pointing to http://oss.sonatype.org with my local Maven repository proxy. That meant subclassing RobolectricTestRunner to org.robolectric.MyRobolectricTestRunner, and creating a custom MavenCentral object for it to use, and overriding the methods where RobolectricTestRunner references its private MAVEN_CENTRAL object.
The source code for RobolectricTestRunner and MavenCentral are available on Robolectric's Github page.
I used Robolectric version 3.0, and the dependency jars were downloaded from my repository, instead of sonatype.
I want to setup my maven settings.xml file to download all the external dependencies from Artifactory cache instead of download them directly from any of the public repositories like repo1, repo2 or Jboss. I followed the instructions at http://wiki.jfrog.org/confluence/display/RTF/Configuring+Artifacts+Resolution at but I'm stuck with an error with the terracota library, the error is:
Could not find artifact net.sf.ehcache:ehcache-terracotta:jar:2.5.0 in remote-repos
I tried adding terracota repository at the remote repositories section but this didn't worked either.
Please advice.
I can think of a couple of possibilities:
Your remote-repos cache isn't configured to point to the remote repository that contains the Terracotta files
Your build isn't using the correct organization or module name when resolving the dependency on Terracotta.
Could you add some info to your question detailing where exactly you are seeing the error message, and whether you can browse to ehcache-terracotta version 2.5.0 in Artifactory ?
Please add the terracotta repository to your artifactory
This is the URL= http://www.terracotta.org/download/reflector/releases
Don't worry if the test of the repo doesn't work...
The last step is to go to Edit Virtual Repository and add the new terracotta repo to the virtual repository called "Remote Repo".