How the exclude directive works in the go.mod file?












0















The new Go version 1.11 introduced the modules concept which is awesome.



In the documentation it says there are four directives that can be used in a go.mod file: module, require, exclude, replace.



It also explains that:




exclude and replace directives only operate on the current (“main”)
module. exclude and replace directives in modules other than the main
module are ignored when building the main module. The replace and
exclude statements therefore allow the main module complete control
over its own build, without also being subject to complete control by
dependencies.




But I still don't understand how the exclude directive works.



Can someone explain to me how the exclude directive works and if possible give an example of when to use it?










share|improve this question



























    0















    The new Go version 1.11 introduced the modules concept which is awesome.



    In the documentation it says there are four directives that can be used in a go.mod file: module, require, exclude, replace.



    It also explains that:




    exclude and replace directives only operate on the current (“main”)
    module. exclude and replace directives in modules other than the main
    module are ignored when building the main module. The replace and
    exclude statements therefore allow the main module complete control
    over its own build, without also being subject to complete control by
    dependencies.




    But I still don't understand how the exclude directive works.



    Can someone explain to me how the exclude directive works and if possible give an example of when to use it?










    share|improve this question

























      0












      0








      0


      1






      The new Go version 1.11 introduced the modules concept which is awesome.



      In the documentation it says there are four directives that can be used in a go.mod file: module, require, exclude, replace.



      It also explains that:




      exclude and replace directives only operate on the current (“main”)
      module. exclude and replace directives in modules other than the main
      module are ignored when building the main module. The replace and
      exclude statements therefore allow the main module complete control
      over its own build, without also being subject to complete control by
      dependencies.




      But I still don't understand how the exclude directive works.



      Can someone explain to me how the exclude directive works and if possible give an example of when to use it?










      share|improve this question














      The new Go version 1.11 introduced the modules concept which is awesome.



      In the documentation it says there are four directives that can be used in a go.mod file: module, require, exclude, replace.



      It also explains that:




      exclude and replace directives only operate on the current (“main”)
      module. exclude and replace directives in modules other than the main
      module are ignored when building the main module. The replace and
      exclude statements therefore allow the main module complete control
      over its own build, without also being subject to complete control by
      dependencies.




      But I still don't understand how the exclude directive works.



      Can someone explain to me how the exclude directive works and if possible give an example of when to use it?







      go






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 0:10









      KelvinSKelvinS

      9831031




      9831031
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Here's a semi-hypothetical hypothetical example:



          go.mod



          module github.com/example/project

          require (
          github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc
          github.com/google/uuid v1.1.0
          )

          exclude github.com/SermoDigital/jose v0.9.1

          replace github.com/google/uuid v1.1.0 => git.coolaj86.com/coolaj86/uuid.go v1.1.1


          exclude



          In the case of the github.com/SermoDigital/jose package, it has a proper git tag for v0.9.1, but the current version is v1.1, which is NOT a proper git tag (missing the "patch" version).



          By excluding the broken version it causes go mod to fetch from master instead.



          replace



          Likewise (and truly hypothetical), if I have a patch to github.com/google/uuid, I can create a fork and use replace to get my own version while I wait for the upstream version to accept my patch (or not).






          share|improve this answer































            0














            Read the whole Modules document. Further down in the document from your quote,




            ... the top-level module in the build can exclude specific versions of
            dependencies or replace other modules with different code. See the
            full proposal for more details and rationale.







            share|improve this answer
























            • Yes, I saw that, but why should I exclude a dependency? In which circumstances?

              – KelvinS
              Nov 26 '18 at 10:01











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473290%2fhow-the-exclude-directive-works-in-the-go-mod-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Here's a semi-hypothetical hypothetical example:



            go.mod



            module github.com/example/project

            require (
            github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc
            github.com/google/uuid v1.1.0
            )

            exclude github.com/SermoDigital/jose v0.9.1

            replace github.com/google/uuid v1.1.0 => git.coolaj86.com/coolaj86/uuid.go v1.1.1


            exclude



            In the case of the github.com/SermoDigital/jose package, it has a proper git tag for v0.9.1, but the current version is v1.1, which is NOT a proper git tag (missing the "patch" version).



            By excluding the broken version it causes go mod to fetch from master instead.



            replace



            Likewise (and truly hypothetical), if I have a patch to github.com/google/uuid, I can create a fork and use replace to get my own version while I wait for the upstream version to accept my patch (or not).






            share|improve this answer




























              1














              Here's a semi-hypothetical hypothetical example:



              go.mod



              module github.com/example/project

              require (
              github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc
              github.com/google/uuid v1.1.0
              )

              exclude github.com/SermoDigital/jose v0.9.1

              replace github.com/google/uuid v1.1.0 => git.coolaj86.com/coolaj86/uuid.go v1.1.1


              exclude



              In the case of the github.com/SermoDigital/jose package, it has a proper git tag for v0.9.1, but the current version is v1.1, which is NOT a proper git tag (missing the "patch" version).



              By excluding the broken version it causes go mod to fetch from master instead.



              replace



              Likewise (and truly hypothetical), if I have a patch to github.com/google/uuid, I can create a fork and use replace to get my own version while I wait for the upstream version to accept my patch (or not).






              share|improve this answer


























                1












                1








                1







                Here's a semi-hypothetical hypothetical example:



                go.mod



                module github.com/example/project

                require (
                github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc
                github.com/google/uuid v1.1.0
                )

                exclude github.com/SermoDigital/jose v0.9.1

                replace github.com/google/uuid v1.1.0 => git.coolaj86.com/coolaj86/uuid.go v1.1.1


                exclude



                In the case of the github.com/SermoDigital/jose package, it has a proper git tag for v0.9.1, but the current version is v1.1, which is NOT a proper git tag (missing the "patch" version).



                By excluding the broken version it causes go mod to fetch from master instead.



                replace



                Likewise (and truly hypothetical), if I have a patch to github.com/google/uuid, I can create a fork and use replace to get my own version while I wait for the upstream version to accept my patch (or not).






                share|improve this answer













                Here's a semi-hypothetical hypothetical example:



                go.mod



                module github.com/example/project

                require (
                github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc
                github.com/google/uuid v1.1.0
                )

                exclude github.com/SermoDigital/jose v0.9.1

                replace github.com/google/uuid v1.1.0 => git.coolaj86.com/coolaj86/uuid.go v1.1.1


                exclude



                In the case of the github.com/SermoDigital/jose package, it has a proper git tag for v0.9.1, but the current version is v1.1, which is NOT a proper git tag (missing the "patch" version).



                By excluding the broken version it causes go mod to fetch from master instead.



                replace



                Likewise (and truly hypothetical), if I have a patch to github.com/google/uuid, I can create a fork and use replace to get my own version while I wait for the upstream version to accept my patch (or not).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 17 '18 at 22:40









                CoolAJ86CoolAJ86

                49.6k106479




                49.6k106479

























                    0














                    Read the whole Modules document. Further down in the document from your quote,




                    ... the top-level module in the build can exclude specific versions of
                    dependencies or replace other modules with different code. See the
                    full proposal for more details and rationale.







                    share|improve this answer
























                    • Yes, I saw that, but why should I exclude a dependency? In which circumstances?

                      – KelvinS
                      Nov 26 '18 at 10:01
















                    0














                    Read the whole Modules document. Further down in the document from your quote,




                    ... the top-level module in the build can exclude specific versions of
                    dependencies or replace other modules with different code. See the
                    full proposal for more details and rationale.







                    share|improve this answer
























                    • Yes, I saw that, but why should I exclude a dependency? In which circumstances?

                      – KelvinS
                      Nov 26 '18 at 10:01














                    0












                    0








                    0







                    Read the whole Modules document. Further down in the document from your quote,




                    ... the top-level module in the build can exclude specific versions of
                    dependencies or replace other modules with different code. See the
                    full proposal for more details and rationale.







                    share|improve this answer













                    Read the whole Modules document. Further down in the document from your quote,




                    ... the top-level module in the build can exclude specific versions of
                    dependencies or replace other modules with different code. See the
                    full proposal for more details and rationale.








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 26 '18 at 2:05









                    peterSOpeterSO

                    96.6k15160180




                    96.6k15160180













                    • Yes, I saw that, but why should I exclude a dependency? In which circumstances?

                      – KelvinS
                      Nov 26 '18 at 10:01



















                    • Yes, I saw that, but why should I exclude a dependency? In which circumstances?

                      – KelvinS
                      Nov 26 '18 at 10:01

















                    Yes, I saw that, but why should I exclude a dependency? In which circumstances?

                    – KelvinS
                    Nov 26 '18 at 10:01





                    Yes, I saw that, but why should I exclude a dependency? In which circumstances?

                    – KelvinS
                    Nov 26 '18 at 10:01


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473290%2fhow-the-exclude-directive-works-in-the-go-mod-file%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Futebolista

                    Feedback on college project

                    Albești (Vaslui)