I would like to use code that I wrote for one project in another project, and it seems like the best way to go about doing this is to use packages, but I'm not exactly sure how, and the documentation I found from my googling on this is pretty unclear. Should I sbt package and then copy the .jar into the project I want to use the code for? How does my build.sbt file need to augmented to do this? If the projects are in the same level directory, is there an easier way of doing this?
SBT has a publish-local command that will package and install you jar file in a local repository. Then you can reference you jar as you would any other dependency.
https://github.com/harrah/xsbt/wiki/Publishing
Related
I have a scala project built with dependancy on a locally built jar file (java code). Once I need to check in my scala code into a different environment for building and deployment, what's the best way to keep my jar file in the dependancy?
I know that if I use the sbt dependancy from online modules, I don't need to worry, it will download the version and build, but what if I want to use my own jar file for this purpose?
This is in OSX, and code will be checked into linux machines, I am using intellij and sbt to manage my scala project. I also used intellij to build my external java lib into jar file and added dependancy of this specific path.
I hope there should be some generic solution, but I am new in JAVA and SBT
I got it figured out. Add the jar files under the lib directory right under the project will solve the problem. SBT will pick it up automatically and you can certainly check in the jar files like source code.
I´ve been googling but I could not find a good documentation.
I create a project with an entry API using macros, but now since I cannot use it even from my own project I need to export it.
Anybody please can point me to a good documentation/blog where explain how to export/import a macro project with intellij?.
Regards.
You don't need to do anything special. Just build it and use it as a dependency of other projects. If you are using SBT, run command sbt publishLocal. Also, you can use macros in other modules of a multi-module project, or in tests (if they are defined in main sources).
We can use IntelliJ-IDEA to import an normal SBT project easily, but I'm trying to write an IDEA plugin project with Scala, and I want to use SBT to manage it(the dependencies).
But now I don't know how to do it, and not sure if it's possible, so I have to use IDEA to create an IDEA plugin project manually, and commit the .idea/* files to git, which is not good.
Is it possible to use SBT to create an IDEA plugin project?
I am not sure how the exact code would look. But the play framework does something like what you want. They let you create an IDEA project with
[My first application] $ idea
So you can .gitignore the .idea/* folder and every developer can easily create their own IDEA project if they want to use an IDE.
Their documentation describes how you use it, so it should be easy enough to find the code that actually generates the project: https://www.playframework.com/documentation/2.0/IDE
I have a setup with 13 different eclipse projects (mostly scala and java). All projects have dependencies on each other in different ways. Now the project is starting to get big so we want to transition to a build tool and I wanted to try SBT.
First question: Is there any way to export the build files from eclipse? I mean, I have everything working in eclipse so It feels like an "export build.sbt" would be possible.
Second question: I have not found any easy way to add the project dependencies in a sbt file. Some sites say that I should publish all projects to a local maven repo and then using dependencies to be able to build it, but that requirement seems a little extreme.
I found my answers by a friendly person on the #sbt irc-channel.
For the first question: No, there seems to be none at the moment.
For the second qestion: I should create a multi-project build and define dependencies between projects that way (following the guide at: http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.html)
Disclaimer: I'm scala beginner. All defaults works nice for me, but whenever I want to have custom layout/build I run into a problem.
So, as part of my build I need to pull .war(web app) from project A and .jar(jetty launcher) from project B into some directory of project C(tanuki service wrapper).
Can anybody please provide an an example how to do this in the most effective way.
Not sure if it works with war files, but for making jars locally available you could use sbt's publish-local command. Say you have an sbt project "mylibrary" and another sbt project "mymain". If you locally publish "mylibrary.jar", you can add it as a dependency to "mymain" just like you add any other sbt-managed dependency, i.e., by adding a line such as
libraryDependencies += "foo.bar.com" %% "mylibrary" % "0.1-SNAPSHOT"
to the build.sbt of "mymain".
If that is not possible you might want to write an sbt plugin/command that copies the files into a given directory. I don't have experience with extending sbt, so I can't help with that, but other stackoverflowers surely can :-)
EDIT: (addressing a comment by the OP)
No, I don't have a particular Sbt tutorial. If I need help I turn to the usual suspects, the wiki, the mailing list, Stackoverflow, Sbt's source code. Sbt has an IO package which offers a copyFile method, which, according to this thread, comes in handy. Searching for 'copying files' on the mailing list also yields other results that might help you.