depclean

DepClean automatically detects and removes unused dependencies in Maven projects πŸ”— https://dx.doi.org/10.1007/s10664-020-09914-8)

https://github.com/assert-kth/depclean

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • βœ“
    CITATION.cff file
    Found CITATION.cff file
  • βœ“
    codemeta.json file
    Found codemeta.json file
  • βœ“
    .zenodo.json file
    Found .zenodo.json file
  • βœ“
    DOI references
    Found 3 DOI reference(s) in README
  • βœ“
    Academic publication links
    Links to: arxiv.org
  • β—‹
    Academic email domains
  • β—‹
    Institutional organization owner
  • β—‹
    JOSS paper metadata
  • β—‹
    Scientific vocabulary similarity
    Low similarity (7.3%) to scientific vocabulary

Keywords

bloatware bytecode debloating dependencies java maven-plugin
Last synced: 4 months ago · JSON representation ·

Repository

DepClean automatically detects and removes unused dependencies in Maven projects πŸ”— https://dx.doi.org/10.1007/s10664-020-09914-8)

Basic Info
  • Host: GitHub
  • Owner: ASSERT-KTH
  • License: mit
  • Language: Java
  • Default Branch: master
  • Homepage:
  • Size: 32.5 MB
Statistics
  • Stars: 279
  • Watchers: 7
  • Forks: 34
  • Open Issues: 17
  • Releases: 10
Topics
bloatware bytecode debloating dependencies java maven-plugin
Created about 6 years ago · Last pushed 5 months ago
Metadata Files
Readme License Citation

README.md

DepClean DepClean logo

build Quality Gate Status Maintainability Rating Reliability Rating Security Rating Maven Central Licence Vulnerabilities Bugs Code Smells Lines of Code Duplicated Lines (%) Technical Debt codecov

What is DepClean?

DepClean is a Maven plugin that automatically detects and removes unused dependencies declared in a project's pom.xml file, imported transitively through other dependencies, and even those inherited from a parent POM.

It can be executed via the command line as a Maven goal or seamlessly integrated into the Maven build lifecycle (e.g., in CI/CD pipelines).

Importantly, DepClean does not modify your source code or original pom.xml file.

Main Features

  • Automatically detects and removes unused dependencies from the pom.xml, including those inherited from parent projects.
  • Fully supports Java 21 bytecode analysis, ensuring compatibility with modern Java features.
  • Generates a clean and minimal pom.xml, free from unused dependencies.
  • Produces detailed, per-dependency usage reports.
  • Offers fine-grained configuration options to tailor the analysis and cleaning process.
  • Integrates directly into the Maven build lifecycle.
  • Handles multi-module Maven projects out of the box.
  • Ignores some dependencies used only via reflection (e.g., frameworks like Spring or Hibernate).
  • Includes support for annotation processors.
  • Analyzes fat JARs, shaded dependencies, and repackaged libraries.

For a visual overview of how DepClean works and what it can do for your project, check out the companion project: depclean-web.

✨ DepClean is the result of academic research conducted at KTH Royal Institute of Technology in Sweden. It was introduced in the paper: "A Comprehensive Study of Bloated Dependencies in the Maven Ecosystem" (DOI: 10.1007/s10664-020-09914-8)

Usage

Configure the pom.xml file of your Maven project to use DepClean as part of the build:

xml <plugin> <groupId>se.kth.castor</groupId> <artifactId>depclean-maven-plugin</artifactId> <version>2.2.0-SNAPSHOT</version> <executions> <execution> <goals> <goal>depclean</goal> </goals> </execution> </executions> </plugin>

Or you can run DepClean directly from the command line.

bash cd {PATH_TO_MAVEN_PROJECT} mvn compile mvn compiler:testCompile mvn se.kth.castor:depclean-maven-plugin:2.2.0-SNAPSHOT:depclean

Let's see an example of running DepClean version 2.0.1 in the project Apache Commons Numbers!

Demo

Optional Parameters

The Maven plugin can be configured with the following additional parameters.

| Name | Type | Description | | :------------------------- | :-----------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | <ignoreDependencies> | Set<String> | A regex expression matching dependencies to be ignored by DepClean during the analysis (i.e., considered as used). This is useful to bypass incomplete result caused by bytecode-level analysis. For example: -DignoreDependencies="net.bytebuddy:byte-buddy:.*","com.google.guava.*" ignores dependencies with groupId:artifactId equals to net.bytebuddy:byte-buddy and groupId equals to com.google.guava. | | <ignoreScopes> | Set<String> | Add a list of scopes, to be ignored by DepClean during the analysis. Useful to not analyze dependencies with scopes that are not needed at runtime. Valid scopes are: compile, provided, test, runtime, system, import. An Empty string indicates no scopes (default). | | <ignoreTests> | boolean | If this is true, DepClean will not analyze the test classes in the project, and, therefore, the dependencies that are only used for testing will be considered unused. This parameter is useful to detect dependencies that have compile scope but are only used for testing. Default value is: false. | | <createPomDebloated> | boolean | If this is true, DepClean creates a debloated version of the pom without unused dependencies called debloated-pom.xml, in the root of the project. Default value is: false. | | <createResultJson> | boolean | If this is true, DepClean creates a JSON file of the dependency tree along with metadata of each dependency. The file is called depclean-results.json, and is located in the target directory of the project. Default value is: false. | | <createCallGraphCsv> | boolean | If this is true, DepClean creates a CSV file with the static call graph of the API members used in the project. The file is called depclean-callgraph.csv, and is located in the target directory of the project. Default value is: false. | | <failIfUnusedDirect> | boolean | If this is true, and DepClean reported any unused direct dependency in the dependency tree, the build fails immediately after running DepClean. Default value is: false. | | <failIfUnusedTransitive> | boolean | If this is true, and DepClean reported any unused transitive dependency in the dependency tree, the build fails immediately after running DepClean. Default value is: false. | | <failIfUnusedInherited> | boolean | If this is true, and DepClean reported any unused inherited dependency in the dependency tree, the build fails immediately after running DepClean. Default value is: false. | | <skipDepClean> | boolean | Skip plugin execution completely. Default value is: false. |

You can integrate DepClean in your CI/CD pipeline. For example, if you want to fail the build in the presence of unused direct dependencies, while ignoring all the dependency scopes except the compile, use the following plugin configuration.

xml <plugin> <groupId>se.kth.castor</groupId> <artifactId>depclean-maven-plugin</artifactId> <version>2.2.0-SNAPSHOT</version> <executions> <execution> <goals> <goal>depclean</goal> </goals> <configuration> <failIfUnusedDirect>true</failIfUnusedDirect> <ignoreScopes>provided,test,runtime,system,import</ignoreScopes> </configuration> </execution> </executions> </plugin>

Of course, it is also possible to execute DepClean with parameters directly from the command line. The previous example can be executed directly as follows:

bash mvn se.kth.castor:depclean-maven-plugin:2.2.0-SNAPSHOT:depclean -DfailIfUnusedDirect=true -DignoreScopes=provided,test,runtime,system,import

How does DepClean works?

DepClean runs before executing the package phase of the Maven build lifecycle. It statically collects all the types referenced in the project under analysis as well as in its declared dependencies. Then, it compares the types that the project actually use in the bytecode with respect to the class members belonging to its dependencies.

With this usage information, DepClean constructs a new pom.xml based on the following steps:

  1. add all used transitive dependencies as direct dependencies
  2. remove all unused direct dependencies
  3. exclude all unused transitive dependencies

If all the tests pass, and the project builds correctly after these changes, then it means that the dependencies identified as bloated can be removed. DepClean produces a file named pom-debloated.xml, located in the root of the project, which is a clean version of the original pom.xml without bloated dependencies.

Installing and building from source

Prerequisites:

In a terminal clone the repository and switch to the cloned folder:

bash git clone https://github.com/castor-software/depclean.git cd depclean

Then run the following Maven command to build the application and install the plugin locally:

bash mvn clean install

License

Distributed under the MIT License. See LICENSE for more information.

Funding

DepClean is partially funded by the Wallenberg Autonomous Systems and Software Program (WASP).

Wallenberg Autonomous Systems and Software Program (WASP)

Owner

  • Name: ASSERT
  • Login: ASSERT-KTH
  • Kind: organization
  • Location: Sweden

assertEquals("Research group at KTH Royal Institute of Technology, Stockholm, Sweden", description);

Citation (CITATION.cff)

cff-version: 1.2.0
preferred-citation:
  type: article
  title: "A Comprehensive Study of Bloated Dependencies in the Maven Ecosystem"
  journal: "Empirical Software Engineering"
  doi: "10.1007/s10664-020-09914-8"
  year: 2021
  volume: 26
  issue: 3
  start: 1
  end: 44  
  authors:
    - family-names: Soto-Valero
      given-names: CΓ©sar
      orcid: "https://orcid.org/0000-0003-0541-6411"
    - family-names: Harrand
      given-names: Nicolas
      orcid: "https://orcid.org/ 0000-0002-2491-2771"
    - family-names: Monperrus
      given-names: Martin
      orcid: "https://orcid.org/0000-0003-3505-3383"
    - family-names: Baudry
      given-names: Benoit
      orcid: "https://orcid.org/0000-0002-4015-4640"

GitHub Events

Total
  • Issues event: 6
  • Watch event: 22
  • Delete event: 65
  • Issue comment event: 205
  • Push event: 171
  • Pull request review comment event: 4
  • Pull request review event: 9
  • Pull request event: 154
  • Fork event: 3
  • Create event: 63
Last Year
  • Issues event: 6
  • Watch event: 22
  • Delete event: 65
  • Issue comment event: 205
  • Push event: 171
  • Pull request review comment event: 4
  • Pull request review event: 9
  • Pull request event: 154
  • Fork event: 3
  • Create event: 63

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 13
  • Total pull requests: 336
  • Average time to close issues: 10 months
  • Average time to close pull requests: 22 days
  • Total issue authors: 12
  • Total pull request authors: 8
  • Average comments per issue: 1.08
  • Average comments per pull request: 0.79
  • Merged pull requests: 262
  • Bot issues: 1
  • Bot pull requests: 312
Past Year
  • Issues: 5
  • Pull requests: 149
  • Average time to close issues: N/A
  • Average time to close pull requests: 10 days
  • Issue authors: 5
  • Pull request authors: 5
  • Average comments per issue: 0.6
  • Average comments per pull request: 1.0
  • Merged pull requests: 108
  • Bot issues: 0
  • Bot pull requests: 128
Top Authors
Issue Authors
  • renovate[bot] (3)
  • Zomis (2)
  • goodale (1)
  • Omega359 (1)
  • patbaumgartner (1)
  • anbusampath (1)
  • krzyk (1)
  • davidkubecka-ext43694 (1)
  • Riduidel (1)
  • commandini (1)
  • Zusel (1)
  • godevox (1)
Pull Request Authors
  • renovate[bot] (405)
  • commandini (14)
  • dependabot[bot] (8)
  • cesarsotovalero (4)
  • patbaumgartner (2)
  • monperrus (1)
  • pmelchi (1)
  • pwaldon (1)
Top Labels
Issue Labels
bug (9) feature (2)
Pull Request Labels
dependencies (8) feature (2)

Dependencies

.github/workflows/build.yml actions
  • actions/cache v2.1.6 composite
  • actions/cache v1 composite
  • actions/checkout v2 composite
  • actions/checkout v2.3.4 composite
  • actions/setup-java v1 composite
  • actions/setup-java v3 composite
  • codecov/codecov-action v1 composite
  • gradle/wrapper-validation-action v1.0.4 composite
.github/workflows/deploy.yml actions
  • actions/checkout v3 composite
  • actions/create-release v1 composite
  • actions/setup-java v2 composite
depclean-core/pom.xml maven
  • org.apache.maven:maven-core 3.8.5 compile
  • org.codehaus.plexus:plexus-component-annotations 2.1.1 compile
  • org.codehaus.plexus:plexus-utils 3.5.0 compile
  • org.jetbrains:annotations 23.1.0 compile
  • com.google.guava:guava 31.1-jre
  • com.thoughtworks.qdox:qdox 2.0.3
  • org.assertj:assertj-core 3.23.1
  • org.jgrapht:jgrapht-core 1.5.1
  • org.ow2.asm:asm 9.4
depclean-core/src/test/resources/basic_spring_maven_project/pom.xml maven
  • org.springframework.boot:spring-boot-starter-thymeleaf
  • org.springframework.boot:spring-boot-starter-web
  • org.springframework.boot:spring-boot-starter-test test
depclean-gradle-plugin/build.gradle maven
  • org.projectlombok:lombok 1.18.22 compileOnly
  • org.slf4j:slf4j-log4j12 1.7.30 implementation
  • se.kth.castor:depclean-core 2.0.3 implementation
  • se.kth.castor:depclean-maven-plugin 2.0.3 implementation
  • org.junit.jupiter:junit-jupiter-api 5.7.0 testImplementation
  • org.spockframework:spock-core 2.0-groovy-3.0 testImplementation
depclean-gradle-plugin/src/test/resources-fts/all_dependencies_unused/build.gradle maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.2 implementation
depclean-gradle-plugin/src/test/resources-fts/all_dependencies_used/build.gradle maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.2 implementation
depclean-gradle-plugin/src/test/resources-fts/debloated_dependencies.gradle_is_correct/build.gradle maven
  • org.mapstruct:mapstruct-processor 1.4.2.Final compileOnly
  • com.fasterxml.jackson.core:jackson-databind 2.12.2 implementation
depclean-gradle-plugin/src/test/resources-fts/json_should_be_correct/build.gradle maven
  • com.jcabi:jcabi-manifests 1.1 implementation
  • commons-codec:commons-codec 1.15 implementation
  • commons-io:commons-io 2.8.0 implementation
depclean-maven-plugin/pom.xml maven
  • org.apache.maven.plugin-testing:maven-plugin-testing-tools 3.3.0 compile
  • org.apache.maven:maven-core 3.8.5 provided
  • org.apache.maven:maven-plugin-api 3.8.5 provided
  • org.apache.maven:maven-project 3.0-alpha-2 provided
  • com.google.code.gson:gson 2.10
  • commons-io:commons-io 2.11.0
  • org.apache.maven.plugin-tools:maven-plugin-annotations 3.6.4
  • org.apache.maven.shared:maven-dependency-tree 3.2.1
  • org.whitesource:maven-dependency-tree-parser 1.0.6
  • se.kth.castor:depclean-core 2.0.6
  • com.soebes.itf.jupiter.extension:itf-assertj 0.11.0 test
  • com.soebes.itf.jupiter.extension:itf-extension-maven 0.11.0 test
  • com.soebes.itf.jupiter.extension:itf-jupiter-extension 0.11.0 test
  • org.assertj:assertj-core 3.23.1 test
depclean-maven-plugin/src/test/resources/MavenInvokerResources/basic_spring_maven_project/pom.xml maven
  • org.springframework.boot:spring-boot-starter-thymeleaf
  • org.springframework.boot:spring-boot-starter-web
  • org.springframework.boot:spring-boot-starter-test test
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/all_dependencies_unused/pom.xml maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.2
  • com.google.guava:guava 31.0.1-jre
  • commons-io:commons-io 2.11.0
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/all_dependencies_used/pom.xml maven
  • org.kohsuke.metainf-services:metainf-services 1.8 compile
  • org.projectlombok:lombok 1.18.24 compile
  • commons-codec:commons-codec 1.15
  • commons-io:commons-io 2.11.0
  • org.apache.commons:commons-lang3 3.12.0
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/debloated_pom_is_correct/pom.xml maven
  • commons-io:commons-io 2.11.0 compile
  • org.mapstruct:mapstruct-processor 1.4.2.Final provided
  • com.fasterxml.jackson.core:jackson-databind 2.12.2
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/ignored_scopes/pom.xml maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.2 provided
  • com.google.guava:guava 31.0.1-jre
  • commons-io:commons-io 2.11.0 test
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/pom.xml maven
  • com.jcabi:jcabi-manifests 1.1
  • commons-codec:commons-codec 1.15
  • commons-io:commons-io 2.8.0
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/processor_used/pom.xml maven
  • org.mapstruct:mapstruct-processor 1.4.2.Final provided
  • com.fasterxml.jackson.core:jackson-databind 2.12.2
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/unused_direct_only/pom.xml maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.6.1
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/unused_inherited_exists/pom.xml maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.2
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/unused_transitive_only/pom.xml maven
  • com.fasterxml.jackson.core:jackson-databind 2.12.2
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/used_indirectly/pom.xml maven
  • org.apache.commons:commons-compress 1.21
  • org.tukaani:xz 1.9
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/used_java_record/pom.xml maven
  • commons-io:commons-io 2.11.0
  • org.apache.commons:commons-compress 1.21
pom.xml maven
  • org.projectlombok:lombok 1.18.24 provided
  • org.slf4j:slf4j-api 2.0.5
  • org.slf4j:slf4j-log4j12 2.0.5
  • org.junit.jupiter:junit-jupiter-api 5.6.2 test
  • org.junit.jupiter:junit-jupiter-engine 5.6.2 test
  • org.junit.vintage:junit-vintage-engine 5.6.2 test
depclean-gradle-plugin/src/test/resources-fts/empty_project/build.gradle maven
depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/empty_project/pom.xml maven