My sbt version is 1.1.5
I read readme in git,and add addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") in plugins.sbt .
When I use enablePlugins(GitVersioning), it's red, "Cannot resolve symbol GitVersioning"
New user to sbt, cannot figure out where did I missed.
Reload project and error will dissapear.
Every change to sbt build definition (e.g. build.sbt, plugins.sbt) requires sbt project rebuild.
If working directly from sbt, type reload or from console sbt reload
If working from IntelliJ, then right click on sbt project and choose Refresh sbt project (rebuild once) or Auto-import (rebuild on every change).
You have to add addSbtPlugin line to project/plugins.sbt file (create it if doesn't exist). Then add enablePlugins(GitVersioning) to your build.sbt (in the root directory of your project).
I use SBT / Console as a prototyping tool and therefore don't want to start with a pre-defined build.sbt file.
What I want to do is to run the sbt tool and then modify the libraryDependencies setting. then run console and go and use my newly imported library. If I need something more. I can exit the console and import more stuff and then come back in the console.
is this possible? or should I always start with a predefined build.sbt file?
set libraryDependencies += group % art % version
I understand ammonite is good at this as well
Imagine I would like to define a sbt task which is the equivalent of
sbt runDev "-Dconfig.resource=dev.conf"
and then call it via
sbt runDev
runDev is custom run-task in that case. How would the part of my build.sbt look like? Ideally I would like to do something like
javaOptions in runDev += "config.resource=application-dev.conf"
I found a solution myself
fork in runDev := true
javaOptions in runDev ++= Seq("-Dconfig.resource=dev.conf")
The fork is important otherwise it wont start a new JVM with the corresponding java options!
I want to change the sbt.ivy.home java option in my build.sbt file. I tried:
javaOptions := Seq("-Dsbt.ivy.home=c:/ivy2/")
But it doesn't work.
It work well on the command line:
sbt update -Dsbt.ivy.home=c:/ivy/
For Ivy home, you can set it via ivyPaths setting.
I have a library compiled to a jar (not an sbt project, no source code, just the jar file) that's not available on a repository.
Is there a way to publish the jar locally so I can add the dependency using the libraryDependencies += "org.xxx" % "xxx" % "1.0" notation? (I already know how to add the file to a project by copying it to the lib folder.)
The publishLocal action is used to publish your project to a local Ivy repository. By default, this local repository is in ${user.home}/.ivy2/local. You can then use this project from other projects on the same machine source
EDIT: Sorry I misread your question. Here is an example to publish a jar or sources to your local ivy repo.
tl;dr I'd call it a trick not a feature of sbt. You've been warned.
Let's say you've got file.jar to publish. As is for any build tool, sbt including, it's to execute tasks that eventually create an artifact - a jar file in most cases - out of the files in a project.
The project sets the coordinates for the artifact.
The trick is to leverage what sbt requires to set up the environment (= the coordinates) for the jar to be published (otherwise you'd have to specify them on command line that may or may not be very user friendly).
Create a build.sbt with the necessary settings - organization, name, version and possibly scalaVersion - and save it where the jar file is.
organization := "org.abc"
name := "my-own-publish-jar"
version := "1.0.0"
scalaVersion := "2.11.3"
packageBin in Compile := file(s"${name.value}_${scalaBinaryVersion.value}.jar")
You may've noticed, the build changes compile:package task to point at the jar file.
That's it.
Execute sbt publishLocal and the jar file should be in the Ivy2 local repository, i.e. ~/.ivy2/local/org.abc/my-own-publish-jar_2.11/1.0.0/jars/my-own-publish-jar_2.11.jar.
protip Writing a plugin to do it with the coordinates specified on command line should be quite easy now.
Let's say you have wetElephant.jar and wetElephant-javadoc.jar files some 3rd party library and corresponding javadocs which you want to publish to your local repo and referrence it from another project using libraryDependencies sbt taskKey.
Here's what you need to do.
Put your libraries (wetElephant.jar and wetElephant-javadoc.jar) into modules\wetElephant
Define project in your build.sbt file (or Build.scala file)
lazy val stolenLib = project
.in(file("modules/wetElephant"))
.settings(
organization := "com.stolenLibs",
name := "wetElephant",
version := "0.1-IDonKnow",
crossPaths := false, //don't add scala version to this artifacts in repo
publishMavenStyle := true,
autoScalaLibrary := false, //don't attach scala libs as dependencies
description := "project for publishing dependency to maven repo, use 'sbt publishLocal' to install it",
packageBin in Compile := baseDirectory.value / s"${name.value}.jar",
packageDoc in Compile := baseDirectory.value / s"${name.value}-javadoc.jar"
)
Call publishLocal task from sbt/activator (I did it from activator and prefixed it with proejct name):
./activator wetElephant/publishLocal
... and read the output to see what and where was published:
/cygdrive/d/devstation-workspace/projects/m4l-patches 1
[info] Loading project definition from D:\devstation-workspace\projects\m4l-patches\project
[info] Set current project to m4l-patches (in build file:/D:/devstation-workspace/projects/m4l-patches/)
[info] Updating {file:/D:/devstation-workspace/projects/m4l-patches/}wetElephant...
[info] Packaging D:\devstation-workspace\projects\m4l-patches\modules\wetElephant\target\wetelephant-0.1-IDonKnow-sources.jar ...
[info] Done packaging.
[info] Wrote D:\devstation-workspace\projects\m4l-patches\modules\wetElephant\target\wetelephant-0.1-IDonKnow.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...4 ....
[info] Done updating.
[info] :: delivering :: com.stolenLibs#wetelephant;0.1-IDonKnow :: 0.1-IDonKnow :: release :: Sun Dec 20 20:09:24 CET 2015
[info] delivering ivy file to D:\devstation-workspace\projects\m4l-patches\modules\wetElephant\target\ivy-0.1-IDonKnow.xml
[info] published wetelephant to C:\Users\pawell\.ivy2\local\com.stolenLibs\wetelephant\0.1-IDonKnow\poms\wetelephant.pom
[info] published wetelephant to C:\Users\pawell\.ivy2\local\com.stolenLibs\wetelephant\0.1-IDonKnow\jars\wetelephant.jar
[info] published wetelephant to C:\Users\pawell\.ivy2\local\com.stolenLibs\wetelephant\0.1-IDonKnow\srcs\wetelephant-sources.jar
[info] published wetelephant to C:\Users\pawell\.ivy2\local\com.stolenLibs\wetelephant\0.1-IDonKnow\docs\wetelephant-javadoc.jar
[info] published ivy to C:\Users\pawell\.ivy2\local\com.stolenLibs\wetelephant\0.1-IDonKnow\ivys\ivy.xml
[success] Total time: 1 s, completed 2015-12-20 20:09:24
Optionally use these libraries in another project
libraryDependencies += "com.stolenLibs" % "wetElephant" % "0.1-IDontKnow"
Disclaimer: I don't know how not to publish sources...
Here is a blog post I followed to push sbt artifact to a maven repository (local and remote) a few months ago.
http://brizzled.clapper.org/id/100/
Try this:
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
I created a sample Play Framework/sbt project that creates a local repository (not just publish-local) here: https://github.com/muymoo/local-ivy-repo-sbt
Specifically look at Build.scala
makeLocalRepoSettings(publishedProjects):_*
and
localRepoArtifacts += "org.apache.ws.security" % "wss4j" % "1.6.9"
These localRepoArtifacts are found in my local ivy repo, but I think you could edit this to work with plain old jar files as well.
To run: play local-repository-created
It is a simpler version of https://github.com/sbt/sbt-remote-control which does a whole lot more in their Build.scala.