gradle - exclude a module in multi-module nested project

Suppose you have a multi-module gradle project with nested structure. Eg: module A depends on B, B depends on C and so on. And you want to exclude module C from A.

So, here's how you can exclude a 'transitive' module prj-C from prj-B at Project A

build.gradle -- at Project A

dependencies {
    implementation ( project(':prj-B')){   //note the parenthesis
        exclude group: 'com.gt', module: 'prj-C'
    }
    //other dependencies
}


Bonus:


If you want to exclude a transitive dependency (not the module) you can do the following:

dependencies {
    implementation 'com.gt:libraryA'{
        exclude group: 'com.gt', name : 'libararyB'
    }
    //other dependencies
}

Java Sort Map by Value

Java Sort Map By Value


The following snippet works for any Type


static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
return map.entrySet()
.stream()
.sorted(comparingByValue())
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

Reverse Order

static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
return map.entrySet()
.stream()
.sorted(comparingByValue(reverseOrder()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}


Complete Code with test!

import java.util.*;

import static java.lang.System.out;
import static java.util.Collections.reverseOrder;
import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toMap;

public class MapUtil {

public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
return map.entrySet()
.stream()
.sorted(comparingByValue())
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

public static <K, V extends Comparable<? super V>> Map<K, V> sortByValueReverseOrder(Map<K, V> map) {
return map.entrySet()
.stream()
.sorted(comparingByValue(reverseOrder()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

public static void main(String[] args) {
Map<Integer, String> unsortedMap = Map.of(
1, "G",
2, "J",
3, "A",
4, "Y",
5, "N",
6, "O");

out.println(sortByValue(unsortedMap));
out.println(sortByValueReverseOrder(unsortedMap));
}

}