Home > front end >  remove and add project dependencies with gradle/intellij
remove and add project dependencies with gradle/intellij

Time:10-07

I am a Java newbie here. I am thinking of a way to remove all the project dependencies. For example in nodejs, we can simply remove the node_module folder and then do an npm install.

I am using Gradle and IntelliJ IDEA

How can I do the following:

  1. Remove the dependencies from the project
  2. Re-add the dependency again
  3. Lastly where do I see all the dependencies along with its version number in IntelliJ

CodePudding user response:

  • To remove dependencies from the project, simply go to your build.gradle file and remove all the lines containing "implementation", "complie" or anything similar.
  • However if you just want to remove them from cache and redownload them simply enter this command in the terminal: "gradle clean build" or in the gradle menu which you can find in the IntelliJ Sidebar press "Reload all gradle projects"
  • To see the version of the dependencies you can either use "Dependencies" new feature of IntelliJ, or find them in the build.gradle file.

more info here

CodePudding user response:

You can Remove the already installed dependencies by using clean command

gradle clean build

The clean task is defined by the java plugin and it simply removes the buildDir folder, thus cleaning everything including leftovers from previous builds which are no longer relevant. Not doing so may result in an unclean build which may be broken due to build artifacts produced by previous builds.

As an example assume that your build contains several tests that were failed and you decided that these are obsolete thus needs to be removed. Without cleaning the test results (using cleanTest task) or the build entirely (by running the clean task) you'll get stuck with the failed tests results which will cause your build to fail. Similar side effects can happen also with resources/classes removed from the sources but remained in the build folder that was not cleaned.

This will remove the old dependencies and build them back together once again .

and about the dependencies , to check Without modules:

gradle dependencies

For android :

 gradle app:dependencies

Note: Replace app with the project module name

Here is a possible solution , Another one would be to create a gradle task inside build.gradle:

subprojects {
    task listAllDependencies(type: DependencyReportTask) {}
}

Then call the task with

gradle listAllDependencies

and one final simple solution is using Project report plugin

Add this to your build.gradle

apply plugin: 'project-report'

And Then generate a HTML report using:

gradle htmlDependencyReport

And here is IntelliJ IDEA specific way .

Hope i helped .

  • Related