I am using sbt assembly to create a library, for internal purposes.
I am publishing this jar to a local artifactory installation, and it works nicely.
However, I still haven't figured out how to add the source code to the assembly creation process, so when I import it in intellij it will also be available (for debugging, etc.)
Thanks!
As I understand when you do assembly it will look all jars,source etc in cache directory i.e /$HOME/.ivy2/cache/ if your name-version-source.jar is available in cache then in your final assembled jar will have source.jar
In your case you publishing it as local so your source,javadoc jars are generated in local directory i.e /$HOME/.ivy2/local/
So here you go publish the jar to central repository not as publishLocal or as hack In your /$HOME/.ivy2/local/artifact-id/group-id/version/ directory docs,jars,ivys,pom,srcs copy those directory to /$HOME/.ivy2/cache/artifact-id/ paste it here
Then try assembly in my case works for me
Related
I'm writing an sbt plugin to help with deployment. It depends on sbt-native-packager. Principally it adds a deploy task. However, I also need it to copy a bash script run-class.sh into the /bin folder of the package.
How do I copy a file from the sbt plugin to my project? Presently my only idea is to add the file to src/main/resources/run-class.sh in the plugin and generate a file using sbt. Then I can supply a Universal mapping to put the file in the sbt-native-packager package.
Is there an easier way to get a file from the plugin into my sbt project?
You are on the right track with Generating files, specifically Generate resources. You can keep your original file either as a resource or String, but important thing is that the files are generated into resourceManaged in Compile, which is under target. This folder is typically skipped from version control.
I am working on a sample scalatra webapp. I have created one more service jar which contains dao and service layer. I want to add this dependency in Scalatra-SBT project. How can i achieve this?
I bundled my service jar using command : SBT package which created a jar. How will i include this jar in web application? Can i add this in build.scala file? or can i copy into any Webapp folder ?
Is it possible to push this jar to local repository and pull it from there when my webapp builds?
Whew! Lots of questions here!
The good news is that SBT can do all of the tasks that you are asking for.
DO NOT copy JAR files around to satisfy dependencies! It will end up in tears, virtually guaranteed. Tools like Ivy and Maven (and by extension, SBT) are here to help.
To push your service jar to a local repo:
The SBT task is publish-local, i.e. sbt publish-local from your service jar's root directory.
You'll see lots of descriptive output, finishing up with lines in the following format:
[info] published services_2.10 to /Users/millhouse/.ivy2/local/services/services_2.10/0.1-SNAPSHOT/jars/services_2.10.jar
You don't need to do anything special in your build.sbt to make this work, as long as you have the name and scalaVersion variables set. Note that this will publish to your local Ivy cache, which is $HOME/.ivy2/local for most people.
To get your Scalatra-SBT webapp to pick up your service jar:
Edit your webapp's project/build.scala, adding this dependency under the libraryDependencies key (there should already be a few dependencies, one per line, put yours somewhere in the middle!):
"services" %% "services" % "0.1-SNAPSHOT",
Perform an sbt clean update and your dependency will be pulled in. If it doesn't work, SBT will give you a list of the places where it looked for the artifacts; compare it closely with the location that they were published to (in the previous step) and you'll probably find a typo; fix it and try again.
Please note that there is a lot more to dependency and release management than I've shown above, but this should be enough to get you going.
How to add GeoSlick library in my Playframework scala Application. I need to use postgres database postGIS functions in my model. Is it possible to add as jar file? How to convert this project as jar file?
For many SBT projects (which GeoSlick obviously is, because it has the typical SBT files like build.sbt) the following procedure gets you an jar you can import in your project.
Clone the GIT repository with git clone https://github.com/ahinz/GeoSlick
Move into the directory and run sbt. This will download all dependencies defined in the project definitions.
If everything was downloaded correctly, type into the sbt shell package and enter.
This last step will compile a SNAPSHOT-jar file and puts it into the directory target/scala-2.10/
I did this for the project you named and it worked fine, producing a file *geoslick_2.10-0.1.0-SNAPSHOT.jar*.
I'm trying to produce a jar file of my project using Eclipse and when I try to use it it is giving me errors as certain files are not being included in the jar file. I recompiled the project again and after generating the jar file it states that "Jar file export finished with warnings" and certain files are exported with compile warnings.
Is there another way to generate a jar file ? I tried using netbeans but its not allowing me to import the project
You can check in the project properties for the dependencies that you're using in your project environment (Project -> Properties -> Java Build Path).
If all the necessary dependencies are not included in the JAR file that you're creating and also not available on the classpath of the target system, then such errors will occur.
You can either pack the required dependencies in your JAR or deploy them separately to your target system - which method you use really depends on whether the dependencies are 3rd party libraries (they should be deployed separately) or home-grown components that are part of the system itself (they should be packaged together).
For example suppose my main Scala project is:
c:\code\mainproject
There is some other java code I need in a separate project
c:\code\secondproject
How can a specify this in the lite version of the configuration file? I have tried
unmanagedClasspath += "C:/code/secondproject"
However it does not even run
If the projects are separate, you should publish the second project locally, add that local repository to the first project (or, more generally, to SBT configuration), and then add the project as a normal dependency.