Quantcast

Idea for a gradle plugin: find unneeded dependencies

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Idea for a gradle plugin: find unneeded dependencies

c-a-m
This post has NOT been accepted by the mailing list yet.
I've tried to create what I think would be a nifty plugin but I'm not sure it is even possible.

The idea is to repeatedly run the compile task, each time removing a different dependency and seeing if it still compiles.  I spent the morning on it.  I get an error trying to change a dependency "You can't change a configuration which is not in unresolved state!".  This post: http://forums.gradle.org/gradle/topics/you_cant_change_a_configuration_which_is_not_in_unresolved_state make me think its not possible.  I think once you compile the dependencies are locked.

Any other ideas on how to do this?  There is the task:
  task dependencyCheck << {
    def deps = project.configurations.compile.dependencies
    println "Dependencies of $project.name"
    deps.each { conf ->
      println (conf)
    }
   
    deps.each { conf ->
      println "Attempting to compile without dependency = $conf"
      project.configurations.compile.dependencies.remove(conf)
      try {
        tasks.compileJava.execute()
        println ("it worked!!");
      } catch (Throwable e) {
        //nothing to do, this was expected.
      }
      project.configurations.compile.dependencies.add(conf)
    }
  }


Running this on a project I got this output:
Attempting to compile without dependency = DefaultExternalModuleDependency{group='org.slf4j', name='slf4j-api', version='1.7.+', configuration='default'}
it worked!!
:as2:dependencyCheck FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '.../lib/build.gradle' line: 90

* What went wrong:
Execution failed for task ':as2:dependencyCheck'.
> You can't change a configuration which is not in unresolved state!
Loading...