BAEL-4090: Setup for errors
This commit is contained in:
parent
7cfede4a58
commit
3b2b8e1421
1
gradle-5/.gitignore
vendored
Normal file
1
gradle-5/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
**/build/**
|
@ -6,6 +6,10 @@ description = "Gradle 5 root project"
|
|||||||
allprojects {
|
allprojects {
|
||||||
apply plugin :"java"
|
apply plugin :"java"
|
||||||
apply plugin :"nebula.lint"
|
apply plugin :"nebula.lint"
|
||||||
|
gradleLint {
|
||||||
|
rules=['unused-dependency']
|
||||||
|
reportFormat = 'text'
|
||||||
|
}
|
||||||
group = "com.baeldung"
|
group = "com.baeldung"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
sourceCompatibility = "1.8"
|
sourceCompatibility = "1.8"
|
||||||
|
@ -2,11 +2,15 @@
|
|||||||
description = "Gradle Unused Dependencies example"
|
description = "Gradle Unused Dependencies example"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// unused dependency sample
|
||||||
implementation('com.google.guava:guava:29.0-jre')
|
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')
|
testImplementation('junit:junit:4.12')
|
||||||
}
|
}
|
||||||
|
|
||||||
gradleLint {
|
|
||||||
rules=['all-dependency']
|
|
||||||
reportFormat = 'text'
|
|
||||||
}
|
|
||||||
|
@ -1,12 +1,42 @@
|
|||||||
package com.baeldung.unused;
|
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 class UnusedDependencies {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello world");
|
System.out.println("Hello world");
|
||||||
|
useGuava();
|
||||||
// List<String> list = ImmutableList.of("Baledung", "is", "cool");
|
useHttpCore();
|
||||||
// System.out.println(list.stream().collect(Collectors.joining(" ")));
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user