Gist: Gradle/ Invalidate Dependency Cache

If you are using Gradle, you probably know that Gradle use a binary metadata chache to store various aspects of dependency resolution (see following gradle doc ).

There might be a point when you would like to invalidate cache for the depedencies. Easiest approach to do it is to invoke following command:

gradle --refresh-dependencies

It in essence state gradle to ignore all local records of metadata cache and perform a dynamic version recalculation, module refresh and relevant artifact download.


Gist: JAVA 8 Stream API: Stream Initialization

Stream represents a sequence of values. Stream API, introduced in JAVA 8 (JSR-355 [1]) enables declarative specification of computation on data. It may also interesting to note that it imposes no restriction on the data source.

Following are the important facts:

  • Stream != Collection
    • It is bound to a data source which can be {collection, array, IO, iterator}
  • Stream does not hold any data
    • It is simply an intermediate data
  • Stream can’t modify its source
    • Good for parallelism.
  • Stream can be infinite.

In this post, we only discuss how to construct a Stream object.

A Stream object can be constructed in the following manner.

    Collection source = /*a collection that will be used as a source of Stream*/; 

Alternatively, Stream contains several builders, as listed below.

  • IntStream: Stream.of(1,3,4)
  • EmptyStream: Stream.empty()
  • InfiniteStream: Stream.iterate(1, n-> n+10)

In the next post, we shall discuss more on how we can use a Stream to specify data transformation in a declarative manner.


[1] JSR-355: Lambda Expression for Java.

Interactive Scala Development with SBT and JRebel

Problem Statement

Scala REPL is a great tool for incrementally develop software. However, its is quite slow as noted here. Alternative: use Simple Build Tool, aka– SBT. SBT, via its tasks such as compile, run, console, facilitates a quick feedback cycle. The command sbt ~compile further provides continuous/incremental compilation model, that is– whenever a .scala file changes, it re-compiles them and generates .class files.

Problem is that in order to reload these changed class files, one has to restart sbt console. In my humble opinion, it seems a bit inconvenient.


JRebel provides dynamic reloading of modified *.class files. In combination with sbt ~compile, this setup leads to an interactive development experience as follows.

  • We run sbt ~compile in one console window
  • In other one, we run run sbt console.

Thus, when we modify Scala source codes, first SBT instance compiles it and generates class files. If we invoke any command in the second SBT instance, JRebel reloads the modified class files and afterwards the command gets executed, as shown below.

Note that JRebel is free for personal use, and it is definitely worth taking a look. For more information about the development flow using JRebel, SBT, Eclipse/IDEA, please have a look at this article which describes the setup process in details, or simply leave a comment.

Maven: Updating Artefact Version in a Multi-Module Project

Using following Maven command, the version of artifacts can be updated in a multi-module maven project.

mvn versions:set -DnewVersion='new-version'

For instance, the following maven command updates the version in POM.xml files of the enclosed moduels to 7.1.0-DEV-SNAPSHOT.

mvn versions:set -DnewVersion='7.1.0-DEV-SNAPSHOT'

Note that, by default this command creates a backup of the existing POM files. In essence, it creates a pom.xml.versionBackup for each POM file. This behavior can be disabled as follows.

mvn versions:set -DnewVersion='7.1.0-DEV-SNAPSHOT' -DgenerateBackupPoms=false

Maven Commands for Building Specific Modules

In my job, we work with a maven multi-module project. While using maven, I have discovered several commands that are quite effective during development. In this post, and in the upcoming posts I am planning to share those.

So, today's post is regarding Maven command to build a specific project. For instance, we have a project, with three modules: A, B, and C, where C depends on B and B depends on A. And we are working with B at this moment. Using following command, we can run different maven phases on module B as follows.

mvn -pl :B clean install 

We can include multiple projects as follows :A, :B.

What is more interesting is that the following command run maven command not only this module, but also the modules that depends on it.

mvn -pl :B clean install -amd 

The above command in effect includes module C.

Using –am command, we can include all the dependencies as well, which is module A in this example.

Hope this helps!