How to create graph dependency between internal projects in sbt? - scala

I know that it is possible to generate graph of library dependencies in sbt, something like:
>sbt dependencyDot
[info] Wrote dependency graph to 'target/dependencies-compile.dot'
> dot target/dependencies-compile.dot -Tpng -o /tmp/dependencies-compile.png
Anyway, the question is: is it possible to create graph containg [only] internal projects? I mean how to include dependencies like:
dependsOn(ProjectRef(file("../../some_module/scala"), "some_module_utils")) on graph?

Related

Dependency diagram in Dart/Flutter?

Is there a way to see how packages in my flutter project depend on each other?
Under packages, I mean internal packages: folders under 'lib'.
Also, it would be great to check for circular dependencies between the packages.
You can use below command to see your flutter app's dependency graph.
flutter pub deps
The dependency information is printed as a tree, a list, or a compact list.
I was also looking for a tool to show internal dependencies but couldn't find one. So I wrote a tool called Lakos to visualize Dart/Flutter library dependencies in Graphviz. Lakos will visualize dependencies inside your project, not external package dependencies. Lakos will also warn about dependency cycles with an exit code.
https://pub.dev/packages/lakos
Example usage:
lakos --metrics . | dot -Tpng -Gdpi=200 -o lakos_example.png
The output will look similar to this:
Layerlens can auto-generate dependency diagrams for your project.

Accessing values in project/Dependencies.scala file in scala code in subproject

I have a multimodule scala project with the following structure -
-A/
-B/
-project/ (root project)
-build.sbt (this has build definition for all the subprojects)
I have an object declared in the project/ folder (lets call this object Dependencies) which contains various constants . Is it possible to access a variable declared in project/Dependencies.scala in scala code inside a subproject(A or B) without creating a dependency of any of the subprojects on the root project.
Please let me know if I need to clarify further.
If you want to make some code from your build definition available for the code in the project, you can use sbt-buildinfo plugin. It's mostly adapted for setting/task keys, but you can use it for any other values defined in your build too.
The way it works is very simple: it uses sourceGenerators to generate a piece of Scala code (with the values from the build) that will be available to the rest of your project sources. So if you don't want to use sbt-buildinfo, you can also generate sources directly. See sbt documentation on Generating files.

where can i find antlib.xml for Scala?

I am trying to run ant build for Scala. I need to know where can I find "antlib.xml" of Scala. I am using Scala on Ubuntu.
I am getting the error like:
[taskdef] Could not load definitions from resource ${scala.home}/tools/ant/antlib.xml. It could not be found.
if you are trying to build recent Scala from source, have a look at https://github.com/scala/scala/blob/2.12.x/README.md#using-the-sbt-build how to do that.
Note - the project uses sbt to build, not ant.
If you want to build Scala 2.10, see this instead:
https://github.com/scala/scala/tree/2.10.x#part-iii-common-use-cases

Unit testing SBT code within the local project

I have an SBT project, within which I have defined a source generator that parses some DB migration scripts in order to make the current DB version available to the application at compile-time.
For example, I might have the following resources:
subproject1/src/main/resources/db/migration/
|- V1__Baseline.sql
|- V2__AddCustomerTable.sql
|- V2_1__Refactor.sql
And I would require my source generator to create a scala object with the field val version = "2.1".
The SBT project is structured as:
project/
|- build.sbt
|- SchemaVersionParser.scala
Where SchemaVersionParser defines the utility functions that are used by build.sbt in order to parse the resources and generate the appropriate file.
Now since this is a key component of my app, I'd like to ensure that the functions in SchemaVersionParser which extract and sort the versions are unit tested.
Is there any supported means of unit testing SBT code residing locally in the one project? I know I can do this if I create a separate SBT plugin, however it'd be nice if I could avoid this.
SBT build definitions are SBT projects. So put test code in project/src/test/scala should be able to access SchemaVersionParser, and to launch the tests you just do sbt test in project directory.

Using SBT 0.10.0 to generate source code with ANTLR3

How would I use the simple build tool (sbt) 0.10.0 to generate any kind of source code based on an ANTLR3 grammar?
I guess I have to use a plugin for something like this, if I want to use the generated code within the same project or a subproject of the same parent project. Are there any existing plugins for SBT 0.10? ...or maybe another solution without using a plugin?
You won't need to use a plugin.
First you will need to define antlr as a dependency. Then you will need to define your source generation task according to this page:
https://github.com/harrah/xsbt/wiki/Common-Tasks
Your task definition is going to look something like this:
sourceGenerators in Compile <+= sourceManaged in Compile map { dir =>
<code to generate source from grammar files>
}
Where the code to generate your source will create a new org.antlr.Tool object with your files as an argument to the constructor. Once you have created a Tool object, then invoke the process method, and your source should be generated.