Publishing / Resolving Custom SBT Plugins with Nexus - scala

I've created my first SBT (1.x) AutoPlugin to add some settings and behavior to projects that use the plugin.
When I publish it locally, everything resolves and works correctly for the projects using the plugin.
However, when I publish the plugin to our private Nexus repository, it fails to resolve for any projects attempting to use it.
I realize that when sbt plugins are published locally, the path is different than 'regular' sbt projects, but they still resolve correctly for projects which use them.
Do I need to publish sbt plugins to a different location within Nexus than our other Scala / SBT-based projects?
And / or, do I need to set up a new resolver for Nexus-hosted SBT plugins?
I know similar questions have been asked previously, but being new to both Nexus and plugin creation, I haven't been able to figure out exactly what I need to do to get the plugin to resolve correctly when publishing to Nexus rather than simply doing a publishLocal and then adding it to the plugins.sbt file of projects meant to use the plugin.
Any assistance would be very much appreciated!

Related

Intellij not picking dependencies from .ivy2 cache folder

I am using Intellij for scala project. I am using babun application for compiling/running/creating assembly jar for my project because in my organization, we can't use maven artifact repository and we have our own for downloading dependencies so I had setup proxy for it in babun(could not see such option for windows command application). Through babun, I downloaded all dependencies as defined in build.sbt and it got downloaded in <USER_DIRECTORY>/.ivy2/cache
Somehow, when I Synchronize my project in Intellij, it doesn't show up any dependencies(under Project Structure->Project Settings->Modules->Dependencies tab) and I get error in my code for all classes that are coming from dependency jars. It was working fine before but IDK what I did wrong suddenly :(
I also tried setting up VM argument Dsbt.ivy.home= but no help.
Also followed article - Changing Ivy Cache Location for sbt projects in IntelliJ IDEA?

Maven setting.xml equivalent for sbt

To keep artifacts separate, origin of packages differentiated and my development environments clean; I use separate settings.xml files for groups of projects. So and I invoke maven with command as:
mvn -s $PROJECT_ROOT/mvn_settings.xml compile
How can I configure sbt in a similar way? My workplace provides an internally hosted JFrog repository which has sbt and Ivy plugins enabled. I have tried looking up search engine with various keyword but couldn't find matching documentation.
I use IntelliJ Idea CE with Scala plugin, if this is relevant.
Edit 1: I want to be able to control where my artifacts are stored, their origin and their association with individual projects.
Edit 2: Consider two settings.xml's
For my random project with minimal libs from maven central: https://pastebin.com/nLc1PGa3
My company's projects in one big bin: https://pastebin.com/R6a4jGQC All from separate sources, in their own respective folders. Also I can move my projects independently, not worrying which dependency link might break something else unrelated.
First grouping things by settings.xml in Maven is not the best way to go. Better is to use the repository manager which can have routes to the particular repositories and to separate repositories and their specific intention. (I'm using a single settings.xml for years which has not been changed. Only the configuration in my repository manager is handling that; This makes life easier and also on CI systems).
Based on the docs of sbt you can configure the proxy repositories like this in the ~/.sbt/repositories file:
[repositories]
local
my-ivy-proxy-releases: http://repo.company.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo.company.com/maven-releases/
Though anytime later or soon I would suggest the same practice as by #khmarbaise to be followed in any of the projects that you are building.
Since there seems to be no point of keeping different folders for repositories if they are from the same group and artifact or even if they are different with maven/sbt providing the support to build different projects using differently specified dependencies.
Similar to maven there can be a Build Settings Concatenation for build.sbt which would work as -
They are appended in this order:
Settings from Build.settings and Project.settings in your .scala files.
Your user-global settings; for example in ~/.sbt/build.sbt you can define settings affecting all your projects.
Settings injected by plugins, see using plugins coming up next.
Settings from .sbt files in the project.
Build definition projects (i.e. projects inside project) have settings from global plugins (~/.sbt/plugins) added. Using plugins
explains this more. Later settings override earlier ones. The entire
list of settings forms the build definition.
So you can override your global build.sbt to specify the repository path using
"Local Maven" at Path.userHome.asFile.toURI.toURL + ".m2/repository"
You should be able to use a Configuration object to do this.
For example in an .sbt file:
val MyConfig = Configurations.config("my-config").extend(Compile)
(resolvers in MyConfig) := Seq(???)
Then when you use the sbt shell you can call
my-config/compile
And it will use the settings you've declared only for that scope.
Then you can declare as many configurations as needed.
I think you are looking for publishing artifacts to your company's internal JFrog repository.
The relevant JFrog documentation can be found here - https://www.jfrog.com/confluence/display/RTF/SBT+Repositories#SBTRepositories-DeployingArtifacts
I was looking at sbt command line help and I found I can set path to local ivy repository using -ivy option.

SBT Resolve Locally from workspace

In SBT/SBT eclipse is there a way to tell eclipse to (temporarily) resolve a dependency from a checked out elipse project rather than from the repository. Basically functionality similar to that offered by the workspace resolver in Ivy DE
My use case here is that I want to make some changes to a library project and instantly see the effect they have on one my applications that uses that library.
If such functioanality is not offered- is there another way I could achieve the desired result?
I don't know if this is the best or fastest way but you could do:
sbt "~publish-local"
In the folder of the external lib to publish to your local repository. Everytime a change is made in that code, it will be compiled and resent to the local repository.
Then just
sbt compile
In your project

How to make Intellij follow sbt GitHub dependencies?

I managed how to add github dependencies to my sbt project following the instructions in this link.
However, Intellij could not find the github dependencies.
After om-nom-nom sugestion, only Scala plugin is needed:
Installing the Scala plugin from a fresh idea install
Import project from external model -> SBT project
? use auto import ?
Register "unregistered Vcs root"
Set module SDK with your JDK folder and adopt it for the project
Write a main file and press ctrl+shift+F10
The step 4 is important because you won't need to keep the working copies of the sub-projects anymore.
Idea creates them inside ~/.IdeaIC13 folder.
This link talks about multi-root Projects and synchronous branch control.
ps. the SBT plugin somehow was disabled and ideia became cofused about a subproject with a (nested) subsubproject.

How to use existing Intellij projects as a I move forward with SBT?

Novice SBT question - Now that I've started with some basic SBT tutorials, I'd like to start using SBT build files (within Intellij) a lot more often. However, there's a couple of problems with this :
1) Existing projects that I currently publish to a jar, and later import into other projects... how do I publish this jar file to my local repository? SBT publish-local doesn't seem to fit my situation, because the project was made in Intellij and is not (yet) an SBT project.
2) Suppose I do convert the project to an SBT build setup (and then import it into Intellij).. how do I configure Intellij to to publish-local (update) each time I build the project? I do not see many configurable settings around SBT within the new Intellij SBT support.
Using Intellij 13 and SBT 0.13.1
Thanks!
to get you started up quickly on using SBT to drive Idea, have a look at my template project called skeleton
It supports most of the basic tasks you'd want to do.
To publish to your repository, use the publish task.
hope that helps!
For publishing, you simply use the publish action:
To specify the repository, assign a repository to publishTo and optionally set the publishing style. For example, to upload to Nexus:
publishTo := Some("Sonatype Snapshots Nexus" at "https://oss.sonatype.org/content/repositories/snapshots")
As for your second question, despite being a JetBrains fanboy, I have found SBT integration quite disappointing. For one thing, as the JetBrains documentation states itself, you need two plugins: their plugin and sbt-idea. You use sbt-idea to synchronize the IDEA module structure with the SBT build, and you use JetBrains' idea-sbt-plugin to execute SBT tasks in the "Before Launch" action in Run Configurations.
It sounds like you want to do an "install" on every build, so "Before Launch" action support isn't useful. I would suggest writing your own custom SBT task to install on build and using the Command Line Tools Console to execute that task with SBT as if from the command line. I know; that indirection is annoying.
Bear in mind one more thing. I have found numerous bugs with idea-sbt-plugin. At least on Mac. JetBrains told me the next version will be much better, and you can see for yourself with the next EAP version.
I certainly welcome others who have managed to have more success than I have to chime in.