简体   繁体   中英

Understanding Versioning in .cabal and stack.yaml Files

Looking at my stack project's project.cabal :

name:                project
version:             0.1.0.0
-- synopsis:
-- description:
homepage:            https://github.com/githubuser/project#readme
license:             BSD3
license-file:        LICENSE
author:              Author name here
maintainer:          example@example.com
copyright:           2017 Author name here
category:            Web
build-type:          Simple
extra-source-files:  README.md
cabal-version:       >=1.10

executable project-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , project
                     , servant-server
                     , base-compat
                     , wai
                     , aeson
                     , blaze-markup
                     , blaze-html
                     , directory
                     , warp
                     , http-media
                     , lucid
                     , time
                     , bytestring
                     , attoparsec
                     , string-conversions
                     , mtl
                     , servant-lucid
  default-language:    Haskell2010
  ghc-options:
    -fwarn-unused-imports

Is it not necessary to specify each library's version? In other words, it seems that I'm only specifying the library, not the version, eg servant-server .

Looking at my stack.yaml , I see:

resolver: lts-9.5

Perhaps that version, ie lts-9.5 , specifies the version of each dependency?

In short, I'm asking about versioning in a stack project.

Correct, it is not necessary to specify the version of a library (in the sense that the parser for .cabal files doesn't require it).

Correct, stack.yaml 's lts-9.5 resolver specifies fixed versions of a large swath of Hackage, probably including everything listed in that cabal file. You can see the exact list of package/version pairs implied by lts-9.5 on the Stackage website .

The community is somewhat divided on which mechanism (version constraints in the .cabal file or version constraints by specifying a fixed package/version pair list in stack.yaml ) is best suited for specifying version bounds, but I think we can unite in agreement that you should use at least one of these two mechanisms. So, while it is technically not necessary to specify version bounds in any way, I encourage you to do so in some way despite that. Your project is very likely not to build correctly (either now or at some time in the future) if you leave out version bounds.

Personally, I also consider it best practice to include version bounds in the .cabal file itself , even if this is just to fix the bounds to exactly what the stackage resolver would choose, so that people who prefer to use cabal for one reason or another will have less trouble with your package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM