Scala library dependencies in internal artifactory pointing outside - scala

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

Related

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?

Publishing into two repositories

I want to be able to publish to 2 repositories.
One remote repository that I can publish to using sbt publish:
publishTo := Some("Remote repository" at "htpp://...")
One local repository (custom directory within project's root) that I can publish to using sbt publish-local. I couldn't find a way to override the default ${ivy.home}/local. I tried:
externalResolvers += Resolver.file("local", file("mydir"))
But that didn't work. I'm guessing that's because I append at the end of the sequence, so I'm not overriding the default one.
Any suggestions?
EDIT: I have a list of proxy repositories in ~/.sbt/repositories. So I want to keep them too.
To overwrite instead of appending to externalResolvers you could use
val remoteRepo = "my-public" at "http://my-nexus-server/content/groups/public/"
val localRepo = Resolver.file("local", file("mydir"))
externalResolvers := Seq(remoteResolver, localRepo)

How can I accessing the scala play plugin from Build.scala

I am not a very sophisticated SBT user, although I have been using it casually for several years. I have made multiple project builds before, but (as always) this particular 'split one project into sub projects' has hit a snag.
The problem
I have a Build.sbt file in the root directory of a project that had the following line in it
lazy val commonPlay = Project(id = "commonPlay", base=file("modules/commonPlay")).
dependsOn(core).enablePlugins(PlayScala)
The important line in it is 'enablePlugins(PlayScala)'. As well as this build.sbt file, I have a plugins.sbt file in the project directory that declared a number of plugins, including "com.typesafe.play" % "sbt-plugin" % "2.2.1"
I am now migrating the project to use a Build.scala file, and in the Build.scala (which is in the project subdirectory) I have the following code
def playModule(dir: String) =
Project(id = dir, base = file(dir), settings = defaultSettings).
enablePlugins(PlayScala)
lazy val core = module("core")
This gives me a 'not found' exception at the PlayScala.
To Date
I've tried messing around with plugins.sbt: adding it under project/project, but decided that I didn't know what I was doing, and I have something of a phobia about not understanding this sort of detail. I had a good read of http://www.scala-sbt.org/0.13.1/docs/Getting-Started/Using-Plugins.html which was very helpful to my understanding, but didn't actually answer the problem.
My expectation is that all I have to do is specify an import, but I'm not sure how to work out what that import would be
Any help would be appreciated
As you can see in this test of the Play framework itself, you need to use play.PlayScala.
Project(id = dir, base = file(dir)).enablePlugins(play.PlayScala)

How can I configure Scalatra (sbt) to find the webapp folder in a different source folder than "main" [duplicate]

By default, Scalatra expects the "webapp" directory to be at src/main/webapp. How could that be changed to, e.g., content/doc-root?
sbt allows for customizing its default directories using something like the following:
scalaSource <<= (baseDirectory)(_ / "src")
So I assume it's just a matter of knowing the right "configuration key" to use...
#Kelsey Gilmore-Innis has the right answer, but since it's not accepted let's break it, break it, break it down.
First, I'm assuming you're following Getting started guide to install Scalatra using g8. Hopefully the same version I just got.
g8 scalatra/scalatra-sbt
What that g8 template did was to set up an sbt 0.13 build which uses scalatra-sbt 0.3.2 plugin:
addSbtPlugin("org.scalatra.sbt" % "scalatra-sbt" % "0.3.2")
This plugin internally uses JamesEarlDouglas/xsbt-web-plugin 0.4.0 to do the webapp-related settings.
xsbt-web-plugin 0.4.0
This is why xsbt-web-plugin becomes relevant even though you just want to change Scalatra's setting. The setting you need to rewire is called webappResources in Compile. How does that work?
rewiring webappResources
To rewire the setting, open project/build.scala. Add
import com.earldouglas.xsbtwebplugin.PluginKeys.webappResources
to the import clauses. Then change settings as follows:
lazy val project = Project (
"foo",
file("."),
settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
organization := Organization,
name := Name,
version := Version,
scalaVersion := ScalaVersion,
resolvers += Classpaths.typesafeReleases,
webappResources in Compile := Seq(baseDirectory.value / "content" / "doc-root"),
...
)
)
Now move src/main/webapp to content/doc-root, reload sbt, and that should be it.
The resource folder is a Jetty property. If you're running embedded Jetty, it's specified here. You can edit it manually or override by setting the PUBLIC environment variable.
You also can override it in your SBT build file. It uses the xsbt-web-plugin to run, and you can override that plugin's settings.
For newer version of xsbt-web-plugin (1.0.0 as of writing) the way of changing source path is different.
First of all corresponding settings were moved to XwpPlugin.webappSettings. And you needs these two
webappSrc in webapp <<= (baseDirectory in Compile) map { _ / "content" / "doc-root" },
webappDest in webapp <<= (baseDirectory in Compile) map { _ / "content" / "doc-root" },
If you dont want to change the sbt settings, you can also do it programmatically by overriding serveStaticResource and using forward
override protected def serveStaticResource(): Option[Any] = {
// check to see if we need to alter the path to find the TRUE disk url
val incUrl = request.getRequestURI
if(incUrl.startsWith("/otherDir")) {
servletContext.resource(request) map { _ =>
servletContext.getNamedDispatcher("default").forward(request, response)
}
} else {
val trueUrl = "/otherdir" + incUrl
Option(servletContext.getRequestDispatcher(trueUrl).forward(request, response))
}
}
Disclaimer: You should also check that it doesn't go into an infinite loop.

Unable to get a type from different package in Scala

I have a project that consists of several subprojects. Let's say, I have three of them:
service
core
common
In my build.scala, I have the following definition
lazy val root = Project ("root", file("."), settings = Info.settings) aggregate(common, core, service)
lazy val common = Project("common", file("common"), settings = Info.settings)
lazy val core = Project ("core", file("appcore"), settings = Info.settings ++ Seq(libraryDependencies ++= dependencies)) dependsOn common
lazy val security = Project ("Service", file("service"), settings = Info.gatewaySettings ++ Seq(resolvers := packageResolvers, libraryDependencies ++= gatewayDeps)) dependsOn(common, core)
I use idea for development and therefore sbt-idea 1.4.0 for the generation of idea specific files.
I have created a class in 'common': User in package com.project.common.domain and I would like to use it from my 'Service' module. I can't. It simply doesn't see it. I have checked the iml file, it contains dependencies.
Have anyone seen this issue?
The problem was that all classes for some reasons were created in /test/scala instead of /main/scala