Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT alternative for maven's dependencyManagement

Tags:

maven

sbt

In our multi-project codebase, we are using Maven as build framework.
However, we have a Play framework based module, for which we have to use SBT build.

In Maven projects, we have dependencyManagement configured through another project called "version" and included in pom.xml, as follows.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.xxxx.release</groupId>
            <artifactId>xxxx-version</artifactId>
            <version>${project.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

This makes sure to pull correct version of dependency jars for the specific build.

Is there a way to achieve same with SBT?

like image 256
kn_pavan Avatar asked Aug 23 '16 10:08

kn_pavan


People also ask

How does sbt resolve dependencies?

Background. update resolves dependencies according to the settings in a build file, such as libraryDependencies and resolvers . Other tasks use the output of update (an UpdateReport ) to form various classpaths. Tasks that in turn use these classpaths, such as compile or run , thus indirectly depend on update .

What is sbt ivy?

sbt (through Ivy) verifies the checksums of downloaded files by default. It also publishes checksums of artifacts by default. The checksums to use are specified by the checksums setting.

What is alternative for Maven?

The best alternative is GNU Make, which is both free and Open Source. Other great apps like Maven are CMake, Gradle, SCons and Meson. Apache Maven is a Java-based tool for build automation and project management (in software development).

What is provided dependency in sbt?

The “provided” keyword indicates that the dependency is provided by the runtime, so there's no need to include it in the JAR file. When using sbt-assembly, we may encounter an error caused by the default deduplicate merge strategy. In most cases, this is caused by files in the META-INF directory.


1 Answers

You can create an in-house sbt plugin that defines something like the follows:

package com.example

import sbt._

object Dependencies {
  // versions
  lazy val akkaVersion = "2.5.22"

  // libraries
  val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion
  val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % akkaVersion
}

After adding the plugin to your Play app, you can write inside build.sbt as follows:

import com.example.Dependencies._

and akkaActor will be available as a name.

like image 162
Eugene Yokota Avatar answered Oct 10 '22 02:10

Eugene Yokota