24

For given cabal project how could unused dependencies packages be retrieved?

Is there a way to get something like warning during cabal install process if there is a package mentioned in project dependency and there is no any usage of it, so it could be removed from dependencies?

  • 1
    I don't think `cabal` is prepared for that yet. It would certainly be a useful feature. – Daniel Fischer May 06 '13 at 00:04
  • 3
    It'd be useful, but it's an engineering challenge right now. It straddles the line between what cabal knows (packages listed in the .cabal file) and what GHC knows (what packages are used). It might not be bad to add it as a standalone utility, but it's probably not practical to include it with by default with `cabal install`. – Carl May 06 '13 at 05:53
  • If you had an answer to http://stackoverflow.com/q/15203191/812053 , the rest would be relatively straightforward... – Ben Millwood May 16 '13 at 09:41

4 Answers4

8

I think the program packunused is what you are looking for.

LambdaStaal
  • 537
  • 2
  • 9
7

There are some options:

  • For GHC 8.6 and earlier, Weeder version 1 by Neil Mitchell can find unused dependencies.
  • For GHC 8.10 and later, there is a warning GHC may emit (with the GHC option -Wunused-packages) when it sees unnecessary packages in the package database. Since Cabal prepares the package database, any unnecessary package is an unused dependency.

Unfortunately, GHC 8.8 is left out.

P. S.   There was recently released a program called prune-juice that should work for GHC 8.8 too.

nevrome
  • 1,471
  • 1
  • 13
  • 28
Ignat Insarov
  • 4,660
  • 18
  • 37
2

cabal-progdeps lists dependencies once the cabal project has been built.

You can check if thay are all used by adding an unused one to your project.

It requires the same Cabal library version used in cabal-install, otherwise it gives errors parsing dist/setup-config.

Gabriel Riba
  • 6,698
  • 2
  • 17
  • 19
1

There is yet another tool:

https://github.com/ndmitchell/weeder https://hackage.haskell.org/package/weeder

It's not yet on Stackage though

nponeccop
  • 13,527
  • 1
  • 44
  • 106