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.
Once you familiarize yourself with how one Maven project builds you automatically know how all Maven projects build saving you immense amounts of time when trying to navigate many projects. On the other hand, SBT is detailed as " An open-source build tool for Scala and Java projects ". It is similar to Java's Maven and Ant.
The settings.xml file configures a Maven installation. It's similar to a pom.xml file but is defined globally or per user. Let's explore the elements we can configure in the settings.xml file. The main, settings element of the settings.xml file, can contain nine possible predefined child elements:
Maven provides a configuration file called settings.xml in which you can customize the settings tag. We are going to see several things you can configure inside the settings tag in the next bullets. The settings.xml could be in two different places:
A settings.xml file is usually found in a couple of places: Global settings in Mavens home directory: ${maven.home}/conf/settings.xml; User settings in the user’s home: ${user.home}/.m2/settings.xml; If both files exist, their contents are merged. Configurations from the user settings take precedence. 4.1. Determine File Location
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With