Merge pull request #9542 from srzamfir/feature/BAEL-4090_Finding_Unused_Gradle_Dependencies
Feature/bael 4090 finding unused gradle dependencies
This commit is contained in:
commit
2e3b36bb56
2
gradle-5/.gitignore
vendored
Normal file
2
gradle-5/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
**/build/**
|
||||||
|
/build/
|
@ -1,54 +1,21 @@
|
|||||||
plugins{
|
plugins{
|
||||||
id "application"
|
id "nebula.lint" version "16.9.0"
|
||||||
}
|
}
|
||||||
apply plugin :"java"
|
|
||||||
|
|
||||||
description = "Java MainClass execution examples"
|
description = "Gradle 5 root project"
|
||||||
|
allprojects {
|
||||||
|
apply plugin :"java"
|
||||||
|
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"
|
||||||
targetCompatibility = "1.8"
|
targetCompatibility = "1.8"
|
||||||
|
|
||||||
ext {
|
repositories {
|
||||||
javaMainClass = "com.baeldung.gradle.exec.MainClass"
|
jcenter()
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
|
||||||
manifest {
|
|
||||||
attributes(
|
|
||||||
"Main-Class": javaMainClass
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
|
||||||
mainClassName = javaMainClass
|
|
||||||
}
|
|
||||||
|
|
||||||
task runWithJavaExec(type: JavaExec) {
|
|
||||||
group = "Execution"
|
|
||||||
description = "Run the main class with JavaExecTask"
|
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
|
||||||
main = javaMainClass
|
|
||||||
}
|
|
||||||
|
|
||||||
task runWithExec(type: Exec) {
|
|
||||||
dependsOn build
|
|
||||||
group = "Execution"
|
|
||||||
description = "Run the main class with ExecTask"
|
|
||||||
commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass
|
|
||||||
}
|
|
||||||
|
|
||||||
task runWithExecJarExecutable(type: Exec) {
|
|
||||||
dependsOn jar
|
|
||||||
group = "Execution"
|
|
||||||
description = "Run the output executable jar with ExecTask"
|
|
||||||
commandLine "java", "-jar", jar.archiveFile.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
task runWithExecJarOnClassPath(type: Exec) {
|
|
||||||
dependsOn jar
|
|
||||||
group = "Execution"
|
|
||||||
description = "Run the mainClass from the output jar in classpath with ExecTask"
|
|
||||||
commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass
|
|
||||||
}
|
|
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
|
||||||
|
1
gradle-5/java-exec/.gitignore
vendored
Normal file
1
gradle-5/java-exec/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/build/
|
47
gradle-5/java-exec/build.gradle
Normal file
47
gradle-5/java-exec/build.gradle
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
apply plugin: "application"
|
||||||
|
|
||||||
|
description = "Java MainClass execution examples"
|
||||||
|
|
||||||
|
ext {
|
||||||
|
javaMainClass = "com.baeldung.gradle.exec.MainClass"
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
"Main-Class": javaMainClass
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClassName = javaMainClass
|
||||||
|
}
|
||||||
|
|
||||||
|
task runWithJavaExec(type: JavaExec) {
|
||||||
|
group = "Execution"
|
||||||
|
description = "Run the main class with JavaExecTask"
|
||||||
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
|
main = javaMainClass
|
||||||
|
}
|
||||||
|
|
||||||
|
task runWithExec(type: Exec) {
|
||||||
|
dependsOn build
|
||||||
|
group = "Execution"
|
||||||
|
description = "Run the main class with ExecTask"
|
||||||
|
commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass
|
||||||
|
}
|
||||||
|
|
||||||
|
task runWithExecJarExecutable(type: Exec) {
|
||||||
|
dependsOn jar
|
||||||
|
group = "Execution"
|
||||||
|
description = "Run the output executable jar with ExecTask"
|
||||||
|
commandLine "java", "-jar", jar.archiveFile.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
task runWithExecJarOnClassPath(type: Exec) {
|
||||||
|
dependsOn jar
|
||||||
|
group = "Execution"
|
||||||
|
description = "Run the mainClass from the output jar in classpath with ExecTask"
|
||||||
|
commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass
|
||||||
|
}
|
3
gradle-5/settings.gradle
Normal file
3
gradle-5/settings.gradle
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
rootProject.name='gradle-5-articles'
|
||||||
|
include 'java-exec'
|
||||||
|
include 'unused-dependencies'
|
1
gradle-5/unused-dependencies/.gitignore
vendored
Normal file
1
gradle-5/unused-dependencies/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/build/
|
8
gradle-5/unused-dependencies/build.gradle
Normal file
8
gradle-5/unused-dependencies/build.gradle
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
description = "Gradle Unused Dependencies example"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation('com.google.guava:guava:29.0-jre')
|
||||||
|
implementation('org.apache.httpcomponents:httpclient:4.5.12')
|
||||||
|
testImplementation('junit:junit:4.12')
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.baeldung.unused;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
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");
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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