BAEL-4090: Setup for errors

This commit is contained in:
Sorin Zamfir 2020-06-19 16:50:21 +03:00
parent 7cfede4a58
commit 3b2b8e1421
4 changed files with 47 additions and 8 deletions

1
gradle-5/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
**/build/**

View File

@ -6,6 +6,10 @@ description = "Gradle 5 root project"
allprojects {
apply plugin :"java"
apply plugin :"nebula.lint"
gradleLint {
rules=['unused-dependency']
reportFormat = 'text'
}
group = "com.baeldung"
version = "0.0.1"
sourceCompatibility = "1.8"

View File

@ -2,11 +2,15 @@
description = "Gradle Unused Dependencies example"
dependencies {
// unused dependency sample
implementation('com.google.guava:guava:29.0-jre')
// indirect dependency sample
implementation('org.apache.httpcomponents:httpclient:4.5.12')
// webjars sample
implementation('org.webjars:jquery:3.1.1')
// empty jars
implementation('org.codehaus.cargo:empty-jar:1.7.13')
// family jar
implementation('org.apache.openjpa:openjpa:3.1.1')
testImplementation('junit:junit:4.12')
}
gradleLint {
rules=['all-dependency']
reportFormat = 'text'
}

View File

@ -1,12 +1,42 @@
package com.baeldung.unused;
import java.lang.reflect.Method;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.http.HttpHeaders;
import org.apache.http.ssl.SSLContextBuilder;
import com.google.common.collect.ImmutableList;
public class UnusedDependencies {
public static void main(String[] args) {
System.out.println("Hello world");
// List<String> list = ImmutableList.of("Baledung", "is", "cool");
// System.out.println(list.stream().collect(Collectors.joining(" ")));
useGuava();
useHttpCore();
useHttpClientWithReflection();
}
private static void useGuava() {
List<String> list = ImmutableList.of("Baledung", "is", "cool");
System.out.println(list.stream()
.collect(Collectors.joining(" ")));
}
private static void useHttpCore() {
SSLContextBuilder.create();
// does not trigger the direct dep violation
System.out.println(HttpHeaders.ACCEPT);
}
private static void useHttpClientWithReflection() {
try {
Class<?> httpBuilder = Class.forName("org.apache.http.impl.client.HttpClientBuilder");
Method create = httpBuilder.getMethod("create", null);
create.invoke(httpBuilder, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}