I have a project (project1) that is built using Maven. There is another project (project2) which uses SBT and is a Scala code base. The jar built by project1 is added as a dependency to project2. Since project2 is using ivy as its repository, how should I handle this in my Build file of project2?
Currently what I do is the following in my Build.scala of project2:
resolvers ++= Seq(
"Local Maven Repository" at "file:///"+Path.userHome+"/Softwares/maven-repo"
),
This way of adding this dependency is a bit problematic as the path to the local maven repo might differ from each developer. Is there a proper way to refer to maven dependencies from within my Scala project?
As a default, I expect that all my developers are following convention and configure SBT with:
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
If you have developers that are not following convention for whatever reason, maybe they are forced to use a network drive or something, then they need to do some local configuration and not check their changes in (a cultural thing).
You could also look up an environment variable but then you still burden your devs with setting that up.
Related
There are a lot of questions and guides about how to include SBT resolver to a project, but still there are no info about what is an SBT resolver and how can it help including dependencies to a project?
sbt resolver is the configuration for repository that contains jars and their dependencies
for example the below is a resolver definition for a repository called Sonatype and it points at snapshot releases (dev versions)
resolvers +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
When you specify a dependncy in sbt (or any other build system for that matter) the build system needs to know where to look to find that dependency. in JVM world a lot of dependencies are stored in the default maven2 repo ( https://repo1.maven.org/maven2/) but sometimes you need to use other custom repositories and you'd define add a resolver for that
In my project I want to use the sbinary library to (de)serialize some case classes to a binary form. I also want to use the latest Scala in the project. Typesafe offers a version of sbinary in their repositories, and they seem to be the only one who are doing so.
So I add the repository and dependency to my build.sbt like so:
scalaVersion := "2.11.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "org.scala-tools.sbinary" %% "sbinary" % "0.4.2"
Surprisingly, this fails. With a dependency defined like this, SBT tries to find the dependency at the url http://repo.typesafe.com/typesafe/releases/org/scala-tools/sbinary/sbinary_2.11.0 whereas it is really located at http://repo.typesafe.com/typesafe/releases/org.scala-tools.sbinary/sbinary_2.11.0. Because SBT replaces the dots in the dependency group id with slashes, it is not able to find the dependency in the place it's in.
I've tried some tricks for building the string in other ways, but they are all useless since SBT replaces the .s by /s in the string after it is evaluated. How can I get SBT to find the dependency at this URL?
Please note that I'm aware that I could simply make this an offline dependency, but I'd prefer to have this build script work out of the box on any computer with SBT installed.
http://repo.typesafe.com/typesafe/releases/org.scala-tools.sbinary/sbinary_2.11.0 is in ivy style. The default style of sbt is maven2 so your resolver doesn't work.
try
resolvers += Resolver.url("Typesafe Repository (ivy)", url("http://repo.typesafe.com/typesafe/releases/"))(Resolver.ivyStylePatterns)
Source: https://groups.google.com/forum/#!topic/simple-build-tool/TY1AoYYvB4k
I need to get hold of the File reference to a specific artifact during the setup phase of my sbt's plugin.
I've tried:
obtaining the ivy home directory, but that basically means assuming where ivy will place the files (they could be even be in a local maven)
parsing System.getProperty("java.class.path"), but it only contains the sbt-launch jar
obtaining the resolved sbt jars from the update.value setting, but it doesn't have any of the plugin's jars in the list! (only the jars for the application being compiled)
Short of invoking the Ivy API manually, is there any way to get the File to the plugin's jar dependency?
NOTE: This is a very specific part of how to write an sbt plugin to launch the app with an agent factored out into a separate question.
got it! adding the dependency explicitly within the source reveals its resolved path:
override val projectSettings = Seq(
libraryDependencies += "com.github.fommil.lion" %% "agent" % "1.0-SNAPSHOT",
javaOptions ++= Seq(s"-Dhack=${update.value}}")
)
has a reference in it!
javafx is now in oracle-jdk.
scalafx gives delicious examples in its repository
The main questions I'm not being able to answer is "How to get started with scalafx"?
How can I add scalafx libary dependencies on my sbt project?
ScalaFX is soon to reach a stable release state.
As I write this you can find the published artifacts for version 1.0.0-M2 on the maven central repo
Adding the dependency to your sbt build should suffice
libraryDependencies += "org.scalafx" %% "scalafx" % "1.0.0-M2"
I did it the following way: I cloned the scalafx repository, build the jar using sbt package, then just copied the resulting jar into lib/ directory of my project. Make sure to reference your ${JAVAFX_HOME}/lib/jfxrt.jar as well.
If you want to use local maven, just run sbt publish-local in your scalafx dir, then add the following dependency to your project:
"org.scalafx" % "scalafx" % "1.0-SNAPSHOT"
(Look up that version in scalafx build.sbt, I pasted what was in mine)
#ayvango i have created a giter8 scalafx project template.just use
g8 jugchennai/scalafx.g8
You just need a new version of JDK, Giter8 and SBT. Dependency settings for javafx, scala, scalafx are predefined! IDE support also available.
URL : https://github.com/jugchennai/scalafx.g8
I think that by now I figured out how to force project dependencies to be downloaded through Nexus. (I did that by explicitly setting externalResolvers to a Seq with only one value:
override lazy val settings = super.settings ++ Seq(
externalResolvers := Seq("Nexus repository" at "http://.../nexus/content/groups/public/")
)
However, if I drop my Ivy cache, SBT still accesses a number of public repositories for getting the plugins. Ideally I would like that to go through Nexus as well, to make sure we are not dependent on those repositories to exist forever. (Which they don't.)
Any clues? (I'm on SBT 0.11.2)
sbt 0.12 added Global repository setting for this purpose.
Define the repositories to use by putting a standalone [repositories] section (see the Launcher Specification page) in ~/.sbt/repositories and pass -Dsbt.override.build.repos=true to sbt. Only the repositories in that file will be used by the launcher for retrieving sbt and Scala and by sbt when retrieving project dependencies.