How to get Project dependencies from SBT console - scala

Is there a way to inspect the dependencies between my projects in my build (in the sbt console)?
I'd like to check if those configs where successful
projectA.dependsOn(projectB)
and
projectC.aggregate(projectD, projectF)

#Mario Camou's answer is valid if you want to see external dependencies. But if you just want to check if dependency configs were successful, you can simply do:
> sbt
$ projects
This should provide info like: (taken from my Mac)
[info] In file:/Users/vaedama/development/projectA/
[info] projectB
which means that your projectA is dependent on projectB
Now if you want to see which project aggregates which project, you can just do:
> sbt // enter SBT prompt
$ projects // view all projects
The result should look like:
[info] In file:/Users/vaedama/development/SimpleProject/
[info] projectC
$ project projectC // switch to the projectC
$ projectInfo // view aggregations
The result should look something like:
[info] projectD/*:projectInfo
[info] ModuleInfo(projectD, projectD,None,None,List(),com.foo.bar,None,None)
[info] projectF/*:projectInfo
[info] ModuleInfo(projectF, projectF,None,None,List(),com.foo.bar,None,None)
which means that your projectC is an aggregate of projectD and projectF

You could try the sbt-dependency-graph plugin from https://github.com/jrudolph/sbt-dependency-graph

To get a list of the project dependencies of the current project one can also do
show projectDependencies

Related

build.properties in SBT multi-project build

I have a multi project build , the structure of the project looks like this:
project
build.properties
plugins.sbt
subprojects
subProj1
project/
build.properties
Now can we have 2 different sbt versions in 2 build.properies files ? Like we use sbt 0.13 in root project and 1.3 under subProj1 ? Or do sbt ignores the build.properties file for subprojects like it uses to do with plugins.sbt ?
build.properties is only relevant to the sbt launcher script which downloads appropriate version artefacts. After sbt "mother ship" is launched then sbtVersion should not be modified anymore as per inspect sbtVesion:
> inspect sbtVersion
[info] Setting: java.lang.String = 1.4.7
[info] Description:
[info] Provides the version of sbt. This setting should not be modified.
Considering project structure in OP, after sbt is launched at the root level, then build.properties files other than <root>/project/build.properties will be ignored.

scala "console" command gives error "Missing scala-library.jar"

Under sbt, if I give "console" to start a REPL shell, I get the following error.
[error] stack trace is suppressed; run 'last scalaInstance' for the full output
[error] (scalaInstance) Missing scala-library.jar
[error] Total time: 1 s, completed Oct 7, 2019 12:45:07 PM
$ sbt scalaVersion
[info] Loading global plugins from C:..\plugins
[info] Loading settings for project test from plugins.sbt ...
[info] Loading project definition from C:xx\test\project
[info] Loading settings for project root from build.sbt ...
[info] scalaVersion
[info] 2.11.12
$ sbt sbtVersion
[info] sbtVersion
[info] 1.3.0
Try
assemblyOption in set: = (assemblyOption in set) .value.copy (includeScala = true)
Source: https://github.com/sbt/sbt-assembly
if this doesn't solve the issue, it could be a compatibility issue with a plugin which you might have installed, it means that you would have to delete the plugin directory in %HOME%. and %HOME%.ivy2 because it caches some artifacts locally.
If you are not able to find the plugin try deleting %HOME%.ivy2 and running the console again, as it will remove the cached artifacts.
You might want to refer
https://pt.coredump.biz/questions/50313823/why-does-running-tests-through-jenkins-user-on-build-slave-fail-with-missing-scalalibraryjar
I hope it helps.
Somewhat unrelated but I ran into this error on one of my projects and deleting all caches (.m2, .ivy2, coursier) was not enough to fix this. I also had to clear out my .sbt folder (I assume emptying the boot directory). Be sure to backup any settings you still might need.
can you try updating scala version in your sbt build?
for example,
scalaVersion := "2.13.0"

Can't integrate AssertJ into TestNG (Java 1.8, Maven)

Added dependency into pom.xml
After adding static import (tried also many with all list) and assertion (AssertThat) - it doesn't work.
import static org.assertj.core.api.Assertions.*;
It's not finding any JAR for AssertJ. After pressing 2 times control+space - there are no suggestions.
I have seen AssertJ working with Idea, please double check your classpath in Idea.
You can check hos maven resolve your dependencies with mvn dependency:tree, you should see something like:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # assertj-examples-java-8 ---
[INFO] org.assertj:assertj-examples-java-8:jar:1.0
[INFO] +- org.assertj:assertj-core:jar:3.12.2-SNAPSHOT:test

How to change sbt version for project

I have build.properties file in the project with the following line:
sbt.version=1.2.8
build.properties file is in the same folder as build.sbt file.
But when I enter the command "sbt about", it reports 1.0.3. Following is the actual output of the command:
/Users/kale> sbt about
[info] Loading settings from idea.sbt ...
[info] Loading global plugins from /Users/kale/.sbt/1.0/plugins
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from
/Users/kale/workspace/gr8Project/myapp/project
[info] Loading settings from build.sbt ...
[info] Set current project to myapp (in build
file:/Users/kale/workspace/gr8Project/myapp/)
[info] This is sbt 1.0.3
[info] The current project is
{file:/Users/kale/workspace/gr8Project/myapp/}myapp 0.1-SNAPSHOT
[info] The current project is built against Scala 2.12.8
[info] Available Plugins: sbt.plugins.IvyPlugin,
sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin,
sbt.plugins.JUnitXmlReportPlugin,
sbt.plugins.Giter8TemplatePlugin, sbtassembly.AssemblyPlugin,
com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin,
com.lucidchart.sbt.scalafmt.ScalafmtPlugin,
com.lucidchart.sbt.scalafmt.ScalafmtSbtPlugin,
scoverage.ScoverageSbtPlugin,
net.virtualvoid.sbt.graph.DependencyGraphPlugin,
sbtdocker.DockerPlugin, Build, Docker
[info] sbt, sbt plugins, and build definitions are using Scala
2.12.4
How can I change sbt version to 1.2.8?
your project structure should be <root>/project/build.properties, and then you should change the sbt version property (see https://github.com/pedrorijo91/play-slick3-steps/blob/master/project/build.properties as an example)
Use sbt about to know the version in use.

scala.io.source.fromFile with sbt subProjects reading from root resource folder

I have a sbt build with multiple subProjects, when trying to use scala.io.source.fromFile it tries to read files from the root project and not from each individual subProject. This is what I need in some cases but in others I want to use the root resource.
What is the idiomatic way of reading from subproject and root resource folders in SBT with subprojects?
It depends on which scope you are calling resourceDirectory from. Here is an example of build with one root project and two sub-projects (from sbt REPL):
> resourceDirectory
[info] alpha/compile:resourceDirectory
[info] /Users/xyz/sbt-tutorial/sub-projects/sub-a/src/main/resources
[info] beta/compile:resourceDirectory
[info] /Users/xyz/sbt-tutorial/sub-projects/sub-b/src/main/resources
[info] root/compile:resourceDirectory
[info] /Users/xyz/sbt-tutorial/sub-projects/src/main/resources
As you can see, calling alpha/compile:resourceDirectory will get you the resource directory for the sub-project called alpha.
If you want the sbt DSL notation for this it will be:
myTask := {
val resDir = (resourceDirectory in (alpha, Compile)).value
...
}
You can replace alpha etc. with ThisBuild if you want to get the resource directory for the root project.