In sbt, I want to publish a project's artifacts to a local folder and then use those artifacts in another project.
In project A, I can publish the artifacts using this:
publishTo := Some(Resolver.file("file", new File( Path.userHome.absolutePath + "/myMavenRepo/releases" )) )
followed by sbt publish. I am able to see the .jar file and other artifacts in the myMavenRepo/releases/ folder.
However, when I add this to project B:
Resolver.file("myRepo", file(Path.userHome.absolutePath + "/myMavenRepo/releases")) transactional()
... then the project A dependency is not resolved.
Am I using these APIs incorrectly?
By the way, I don't want to use publishLocal because these are experimental projects and don't want them to pollute the repository under ~/.sbt/ folder.
Related
I have a project which depends on a 3rd party jar SomeJar.jar.
How can I make a specific sub project cause this jar to be published to local repository before the sub project runs its own compile?
In the example below, somejar-common needs to first be published to local repo.
lazy val subproj1 = (project in file("subproj1"))
.settings(libraryDependencies += "org.someorg" % "somejar-common" % "1.0.0") // This one needs to be deployed first to local repo
If your (sub)project depends on a fixed jar, you don't need to publish it locally to work with it. You can add it as an unmanaged dependency: just put it in your (sub)project's lib/ subfolder.
See sbt documentation on unmanaged dependencies.
Is it possible to include a dependency from github?
The repository does not have a jar file, just a build.sbt file and a source folder.
You can create a new project which points to the source in your build.sbt and then use dependsOn:
lazy val projectIDependOn = RootProject(uri("git://github.com/user/Project.git"))
lazy val myProject = project in file("my-project").dependsOn(projectIDependOn)
An alternative approach would be to clone to github repository and then use sbt-assembly to create an uber JAR you can use, but that requires a bit more work.
I'm trying to create a standalone jar file from the elastic4s sources on github. I've used sbt compile as detailed on the github page, but I can't find the jar file.
How do I use sbt to create the jar file so I can import it into my projects as a dependency?
The compile task will only compile the project.
> help compile
Compiles sources.
If you want to create a jar file and use it as a dependency in your project, you have two ways of doing that.
Unmanaged dependency (not recommended)
Unmanaged dependency run +package, which will create a jar file for each supported scala version, which you can use in your projects as an unmanaged dependency. Copy the package-generated jar to lib folder in your project.
The jar files will be located in target/scala-2.11 and target/scala-2.10, depending on the Scala version you want to use it with.
Publish to Local Repository (recommended yet imperfect)
If you want to include your custom-built elastic4s, as a managed dependency, you have to run +publishLocal. This will do the same as above, but additionally it will publish the artifact to your local repository. Assuming you've built it with version := "1.2.1.1-SNAPSHOT", you can include it in your project by just adding:
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s" % "1.2.1.1-SNAPSHOT"
What makes the approach imperfect is that once you shared the project on GitHub (or any other project sharing platform), people will have to do publishLocal themselves to be able to build your project. The dependency should therefore go to one of the official binary repositories so when a dependency is needed, it's downloaded from Internet. Consult Publishing.
What is the + character in front of the commands
The + in the commands is for cross-building, if you don't use it the command will be executed only using scalaVersion declared in the build.sbt of the project.
How I can delete my project from local repository? I previously published it using publish-local SBT command.
I want to clean all compiled and cached stuff because I don't see any changes in my project after recompiling it and redeploying on server.
If you want to retry sbt publishLocal, add your module version x.x.x-SNAPSHOT.
Run publishLocal again and note where it writes the published jars to. For me, it was ~/.ivy2/local. Removing this directory cleared the locally published repository.
There is a sbt command clean. if you need you can add additional folders to clean task in your build file
cleanFiles <+= baseDirectory { base => base / "temp" }
I have an SBT Project that creates a JAR file using some external tool (all working fine), i.e. it's not compiling source code. I have the Maven Repo correctly configured with correct Credentials but I am struggling to figure out how to configure the artifact so it publishes the generated JAR file.
My JAR file is "target/my.jar".
I've overridden artifacts as follows:
override def artifacts = Set(Artifact("my.jar", "jar", "jar"))
publish outputs the following
No dependency configuration found, using defaults.
[info] :: publishing :: org.foo#my-project_2.9.0
Can anyone point me in the right direction with this neat tool?
Thanks!
Did you set up the publishTo like this:
override def managedStyle = ManagedStyle.Maven
val publishTo = "My Repo" at "http://foo.bar/content/repositories/releases"
Then you run the 'publish' action. You can also do 'publish local'.