Skip to content
Permalink
Browse files

Unused deps check (#171)

* Save for later

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.

* Check for unused dependencies

Add a task to check for unused dependencies in
dependencies.gradle. This file should only contain
dependencies explicitly added to a configuration
in root project or some subprojects.
  • Loading branch information...
weiminyu committed Jul 15, 2019
1 parent 633dd88 commit 62eab98921ed0262d19600a18313976cb55048fb
Showing with 66 additions and 39 deletions.
  1. +46 −0 build.gradle
  2. +18 −0 buildSrc/build.gradle
  3. +2 −39 dependencies.gradle
@@ -251,3 +251,49 @@ subprojects {
}
}
}

task checkDependenciesDotGradle {
def buildSrcDepsFile = File.createTempFile('buildSrc', 'deps')
buildSrcDepsFile.deleteOnExit()
dependsOn createGetBuildSrcDirectDepsTask(buildSrcDepsFile)

doLast {
Set<String> depsInUse = []
allprojects {
configurations.all {
it.dependencies.findAll { it.group != null }.each {
// Note: .toString() is required since GString should
// not be mixed with Java Strings.
depsInUse.add("${it.group}:${it.name}".toString())
}
}
}
if (buildSrcDepsFile.exists()) {
depsInUse.addAll(buildSrcDepsFile.readLines())
}
def unusedDeps =
rootProject.dependencyMap.keySet()
.findAll { !depsInUse.contains(it) }
.toSorted()

if (unusedDeps.isEmpty()) {
return
}
logger.error(
"Unused dependencies in dependencies.gradle:\n${unusedDeps.toListString()}")
throw new IllegalStateException(
"The dependencies.gradle file should only contain direct dependencies.")
}
}
tasks.build.dependsOn(tasks.checkDependenciesDotGradle)

def createGetBuildSrcDirectDepsTask(outputFileName) {
return tasks
.create(
"getBuildSrcDeps_${java.util.UUID.randomUUID()}".toString(),
Exec) {
workingDir "${rootDir}/buildSrc"
commandLine '../gradlew', 'exportDenpendencies',
"-PdependencyExportFile=${outputFileName}"
}
}
@@ -89,3 +89,21 @@ gradle.projectsEvaluated {
options.compilerArgs << "-Xlint:unchecked"
}
}

task exportDenpendencies {
def outputFileProperty = 'dependencyExportFile'
def output = project.hasProperty(outputFileProperty)
? new PrintStream(
new File(project.getProperty(outputFileProperty)))
: System.out

doLast {
project.configurations.all {
it.dependencies.findAll {
it.group != null
}.each {
output.println("${it.group}:${it.name}")
}
}
}
}
@@ -13,20 +13,17 @@
// limitations under the License.

ext {
// Direct dependencies and compile-time transitive dependencies (i.e.,
// those flagged as undeclared-dependency by Nebula-lint).
dependencyList = [
'args4j:args4j:2.0.26',
'com.beust:jcommander:1.60',
'com.google.api-client:google-api-client:1.29.2',
'com.google.api-client:google-api-client-appengine:1.29.2',
'com.google.api-client:google-api-client-jackson2:1.20.0',
'com.google.api-client:google-api-client-java6:1.27.0',
'com.google.api-client:google-api-client-servlet:1.29.2',
'com.google.apis:google-api-services-admin-directory:directory_v1-rev72-1.22.0',
'com.google.apis:google-api-services-appengine:v1-rev101-1.25.0',
'com.google.apis:google-api-services-bigquery:v2-rev325-1.22.0',
'com.google.apis:google-api-services-clouddebugger:v2-rev8-1.22.0',
'com.google.apis:google-api-services-cloudkms:v1-rev12-1.22.0',
'com.google.apis:google-api-services-cloudresourcemanager:v1-rev6-1.22.0',
'com.google.apis:google-api-services-dataflow:v1b3-rev196-1.22.0',
'com.google.apis:google-api-services-dns:v2beta1-rev6-1.22.0',
'com.google.apis:google-api-services-drive:v2-rev160-1.19.1',
@@ -35,38 +32,27 @@ ext {
'com.google.apis:google-api-services-sheets:v4-rev483-1.22.0',
'com.google.apis:google-api-services-storage:v1-rev150-1.22.0',
'com.google.appengine:appengine-api-1.0-sdk:1.9.48',
'com.google.appengine:appengine-api-labs:1.9.48',
'com.google.appengine:appengine-api-stubs:1.9.48',
'com.google.appengine:appengine-remote-api:1.9.48',
'com.google.appengine:appengine-testing:1.9.58',
'com.google.appengine:appengine-tools-sdk:1.9.48',
'com.google.appengine.tools:appengine-gcs-client:0.6',
'com.google.appengine.tools:appengine-mapreduce:0.9',
'com.google.appengine.tools:appengine-pipeline:0.2.13',
'com.google.auth:google-auth-library-credentials:0.16.1',
'com.google.auth:google-auth-library-oauth2-http:0.16.1',
'com.google.auto:auto-common:0.8',
'com.google.auto.factory:auto-factory:1.0-beta3',
'com.google.auto.value:auto-value:1.6.3',
'com.google.auto.value:auto-value-annotations:1.6.3',
'com.google.closure-stylesheets:closure-stylesheets:1.5.0',
'com.google.cloud:google-cloud-core:1.59.0',
'com.google.cloud:google-cloud-storage:1.59.0',
'com.google.cloud.bigdataoss:gcsio:1.4.5',
'com.google.cloud.bigdataoss:util:1.4.5',
'com.googlecode.charts4j:charts4j:1.3',
'com.google.code.findbugs:jsr305:3.0.2',
'com.google.code.gson:gson:2.8.5',
'com.googlecode.json-simple:json-simple:1.1.1',
'com.google.dagger:dagger:2.21',
'com.google.dagger:dagger-compiler:2.21',
'com.google.dagger:dagger-producers:2.21',
'com.google.errorprone:error_prone_annotations:2.3.3',
'com.google.errorprone:javac-shaded:9-dev-r4023-3',
'com.google.flogger:flogger:0.1',
'com.google.flogger:flogger-system-backend:0.1',
'com.google.gdata:core:1.47.1',
'com.google.googlejavaformat:google-java-format:1.4',
'com.google.guava:guava:27.1-jre',
'com.google.guava:guava-testlib:25.0-jre',
'com.google.gwt:gwt-user:2.8.2',
@@ -78,89 +64,66 @@ ext {
'com.google.monitoring-client:metrics:1.0.4',
'com.google.monitoring-client:stackdriver:1.0.4',
'com.google.oauth-client:google-oauth-client:1.29.2',
'com.google.oauth-client:google-oauth-client-appengine:1.29.2',
'com.google.oauth-client:google-oauth-client-java6:1.27.0',
'com.google.oauth-client:google-oauth-client-jetty:1.28.0',
'com.google.oauth-client:google-oauth-client-servlet:1.29.2',
'com.google.protobuf:protobuf-java:2.6.0',
'com.google.re2j:re2j:1.1',
'com.google.template:soy:2018-03-14',
'com.google.truth.extensions:truth-java8-extension:0.45',
'com.google.truth:truth:0.45',
'com.ibm.icu:icu4j:57.1',
'com.jcraft:jsch:0.1.55',
'com.jcraft:jzlib:1.1.3',
'commons-codec:commons-codec:1.10',
'commons-logging:commons-logging:1.2',
'com.squareup:javapoet:1.8.0',
'com.squareup:javawriter:2.5.1',
'com.sun.activation:javax.activation:1.2.0',
'com.sun.xml.bind:jaxb-impl:2.2.11',
'com.sun.xml.bind:jaxb-osgi:2.2.11',
'com.sun.xml.bind:jaxb-xjc:2.2.11',
'com.thoughtworks.paranamer:paranamer:2.7',
'com.thoughtworks.qdox:qdox:1.12.1',
'dnsjava:dnsjava:2.1.7',
'io.netty:netty-buffer:4.1.31.Final',
'io.netty:netty-codec:4.1.31.Final',
'io.netty:netty-codec-http:4.1.31.Final',
'io.netty:netty-common:4.1.31.Final',
'io.netty:netty-handler:4.1.31.Final',
'io.netty:netty-resolver:4.1.28.Final',
'io.netty:netty-tcnative:2.0.22.Final',
'io.netty:netty-tcnative-boringssl-static:2.0.22.Final',
'io.netty:netty-transport:4.1.31.Final',
'it.unimi.dsi:fastutil:6.5.16',
'javax.annotation:jsr250-api:1.0',
'javax.inject:javax.inject:1',
'javax.mail:mail:1.4',
'javax.servlet:servlet-api:2.5',
'javax.xml.bind:jaxb-api:2.3.0',
'javax.xml.soap:javax.xml.soap-api:1.4.0',
'jline:jline:1.0',
'joda-time:joda-time:2.9.2',
'junit:junit:4.12',
'org.apache.avro:avro:1.8.2',
'org.apache.beam:beam-runners-direct-java:2.11.0',
'org.apache.beam:beam-runners-google-cloud-dataflow-java:2.11.0',
'org.apache.beam:beam-sdks-common-runner-api:2.2.0',
'org.apache.beam:beam-sdks-java-core:2.11.0',
'org.apache.beam:beam-sdks-java-extensions-google-cloud-platform-core:2.11.0',
'org.apache.beam:beam-sdks-java-io-google-cloud-platform:2.11.0',
'org.apache.commons:commons-compress:1.8.1',
'org.apache.commons:commons-text:1.6',
'org.apache.ftpserver:ftplet-api:1.0.6',
'org.apache.ftpserver:ftpserver-core:1.0.6',
'org.apache.httpcomponents:httpclient:4.5.2',
'org.apache.httpcomponents:httpcore:4.4.4',
'org.apache.mina:mina-core:2.0.4',
'org.apache.sshd:sshd-core:2.0.0',
'org.apache.sshd:sshd-scp:2.0.0',
'org.apache.sshd:sshd-sftp:2.0.0',
'org.apache.tomcat:tomcat-annotations-api:8.0.5',
'org.bouncycastle:bcpg-jdk15on:1.61',
'org.bouncycastle:bcpkix-jdk15on:1.61',
'org.bouncycastle:bcprov-jdk15on:1.61',
'org.codehaus.jackson:jackson-core-asl:1.9.13',
'org.codehaus.jackson:jackson-mapper-asl:1.9.13',
'org.glassfish.jaxb:jaxb-runtime:2.3.0',
'org.hamcrest:hamcrest-all:1.3',
'org.hamcrest:hamcrest-core:1.3',
'org.hamcrest:hamcrest-library:1.3',
'org.joda:joda-money:0.10.0',
'org.json:json:20160810',
'org.khronos:opengl-api:gl1.1-android-2.1_r1',
'org.mockito:mockito-core:2.25.0',
'org.mortbay.jetty:jetty:6.1.26',
'org.mortbay.jetty:jetty-util:6.1.26',
'org.seleniumhq.selenium:selenium-api:3.141.59',
'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59',
'org.seleniumhq.selenium:selenium-java:3.141.59',
'org.seleniumhq.selenium:selenium-remote-driver:3.141.59',
'org.slf4j:slf4j-api:1.7.16',
'org.testcontainers:selenium:1.10.7',
'org.tukaani:xz:1.8',
'org.xerial.snappy:snappy-java:1.1.4-M3',
'org.yaml:snakeyaml:1.17',
'xerces:xmlParserAPIs:2.6.2',
'xpp3:xpp3:1.1.4c'

0 comments on commit 62eab98

Please sign in to comment.
You can’t perform that action at this time.