where to define test maven dependencies












3















I want to supply test dependencies like spring, mockito and junit in every project to make it as easy as possible to write tests.
Should I use dependency management for this dependencies or define them in the parent pom?










share|improve this question




















  • 1





    Dependency management. And maybe you should think about a convenient parent like Spring Boot does...

    – khmarbaise
    Jan 2 at 11:49
















3















I want to supply test dependencies like spring, mockito and junit in every project to make it as easy as possible to write tests.
Should I use dependency management for this dependencies or define them in the parent pom?










share|improve this question




















  • 1





    Dependency management. And maybe you should think about a convenient parent like Spring Boot does...

    – khmarbaise
    Jan 2 at 11:49














3












3








3








I want to supply test dependencies like spring, mockito and junit in every project to make it as easy as possible to write tests.
Should I use dependency management for this dependencies or define them in the parent pom?










share|improve this question
















I want to supply test dependencies like spring, mockito and junit in every project to make it as easy as possible to write tests.
Should I use dependency management for this dependencies or define them in the parent pom?







java maven testing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 8:12







Philipp

















asked Jan 2 at 11:22









PhilippPhilipp

204




204








  • 1





    Dependency management. And maybe you should think about a convenient parent like Spring Boot does...

    – khmarbaise
    Jan 2 at 11:49














  • 1





    Dependency management. And maybe you should think about a convenient parent like Spring Boot does...

    – khmarbaise
    Jan 2 at 11:49








1




1





Dependency management. And maybe you should think about a convenient parent like Spring Boot does...

– khmarbaise
Jan 2 at 11:49





Dependency management. And maybe you should think about a convenient parent like Spring Boot does...

– khmarbaise
Jan 2 at 11:49












3 Answers
3






active

oldest

votes


















2














Yes , You don't need to define the dependency in every project. Just define the dependency in parent pom. Child project will automatically inherits its parent pom. Also If you want to use different version of Mockito or anything. Just override the parent dependency in child one.






share|improve this answer































    2














    All the common dependencies can be mentioned in the parent pom file. There mainly 4 types of dependencies that can be mentioned in a pom file.




    1. Library Dependencies created by ourselves

    2. Module Dependencies from our own modules

    3. 3rd Party library Dependencies

    4. Dependencies for tests


    Example



    <dependencies>
    <!-- Library Dependencies created by ourselves -->
    <dependency>
    <groupId>it.myapp</groupId>
    <artifactId>MyAppBootstrap</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>it.myapp.libs</groupId>
    <artifactId>b2b_connecttion</artifactId>
    </dependency>

    <!-- Module Dependencies from our own modules-->
    <dependency>
    <groupId>it.myapp.mymodules</groupId>
    <artifactId>RevenueManager</artifactId>
    <version>${myapp.module.version}</version>
    <classifier>classes</classifier>
    </dependency>

    <!-- 3rd Party Dependency -->
    <dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-vfs2</artifactId>
    <scope>provided</scope>
    </dependency>

    <!-- Dependencies for tests -->
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.jmockit</groupId>
    <artifactId>jmockit</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>





    share|improve this answer

































      1














      there are two ways to achieve it -




      1. you declare the dependencies in the parent pom in the <dependencies /> node, and each child will benefit from the dependency.


      2. Add the dependencies in the parent pom under the <dependencyManagement /> node and in each child that requires it, add the dependency in the node. You can choose not to set the version of the dependency.



      So for example, if you declare this in the parent pom:



      <dependencies>
      <dependency>
      <groupId>org.abc</groupId>
      <artifactId>xyz</artifactId>
      <version>your_version</version>
      </dependency>
      </dependencies>
      <dependencyManagement>
      <dependencies>
      <dependency>
      <groupId>org.abc</groupId>
      <artifactId>xyz</artifactId>
      <version>your_version</version>
      <scope>your_scope</scope>
      </dependency>
      </dependencies>
      </dependencyManagement>





      share|improve this answer























        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%2f54005418%2fwhere-to-define-test-maven-dependencies%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        Yes , You don't need to define the dependency in every project. Just define the dependency in parent pom. Child project will automatically inherits its parent pom. Also If you want to use different version of Mockito or anything. Just override the parent dependency in child one.






        share|improve this answer




























          2














          Yes , You don't need to define the dependency in every project. Just define the dependency in parent pom. Child project will automatically inherits its parent pom. Also If you want to use different version of Mockito or anything. Just override the parent dependency in child one.






          share|improve this answer


























            2












            2








            2







            Yes , You don't need to define the dependency in every project. Just define the dependency in parent pom. Child project will automatically inherits its parent pom. Also If you want to use different version of Mockito or anything. Just override the parent dependency in child one.






            share|improve this answer













            Yes , You don't need to define the dependency in every project. Just define the dependency in parent pom. Child project will automatically inherits its parent pom. Also If you want to use different version of Mockito or anything. Just override the parent dependency in child one.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 2 at 11:31









            praneet droliapraneet drolia

            2441314




            2441314

























                2














                All the common dependencies can be mentioned in the parent pom file. There mainly 4 types of dependencies that can be mentioned in a pom file.




                1. Library Dependencies created by ourselves

                2. Module Dependencies from our own modules

                3. 3rd Party library Dependencies

                4. Dependencies for tests


                Example



                <dependencies>
                <!-- Library Dependencies created by ourselves -->
                <dependency>
                <groupId>it.myapp</groupId>
                <artifactId>MyAppBootstrap</artifactId>
                <scope>provided</scope>
                </dependency>
                <dependency>
                <groupId>it.myapp.libs</groupId>
                <artifactId>b2b_connecttion</artifactId>
                </dependency>

                <!-- Module Dependencies from our own modules-->
                <dependency>
                <groupId>it.myapp.mymodules</groupId>
                <artifactId>RevenueManager</artifactId>
                <version>${myapp.module.version}</version>
                <classifier>classes</classifier>
                </dependency>

                <!-- 3rd Party Dependency -->
                <dependency>
                <groupId>com.sun.xml.ws</groupId>
                <artifactId>jaxws-rt</artifactId>
                <scope>provided</scope>
                </dependency>
                <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc7</artifactId>
                <scope>provided</scope>
                </dependency>
                <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-vfs2</artifactId>
                <scope>provided</scope>
                </dependency>

                <!-- Dependencies for tests -->
                <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <scope>provided</scope>
                </dependency>
                <dependency>
                <groupId>org.jmockit</groupId>
                <artifactId>jmockit</artifactId>
                <scope>test</scope>
                </dependency>
                </dependencies>





                share|improve this answer






























                  2














                  All the common dependencies can be mentioned in the parent pom file. There mainly 4 types of dependencies that can be mentioned in a pom file.




                  1. Library Dependencies created by ourselves

                  2. Module Dependencies from our own modules

                  3. 3rd Party library Dependencies

                  4. Dependencies for tests


                  Example



                  <dependencies>
                  <!-- Library Dependencies created by ourselves -->
                  <dependency>
                  <groupId>it.myapp</groupId>
                  <artifactId>MyAppBootstrap</artifactId>
                  <scope>provided</scope>
                  </dependency>
                  <dependency>
                  <groupId>it.myapp.libs</groupId>
                  <artifactId>b2b_connecttion</artifactId>
                  </dependency>

                  <!-- Module Dependencies from our own modules-->
                  <dependency>
                  <groupId>it.myapp.mymodules</groupId>
                  <artifactId>RevenueManager</artifactId>
                  <version>${myapp.module.version}</version>
                  <classifier>classes</classifier>
                  </dependency>

                  <!-- 3rd Party Dependency -->
                  <dependency>
                  <groupId>com.sun.xml.ws</groupId>
                  <artifactId>jaxws-rt</artifactId>
                  <scope>provided</scope>
                  </dependency>
                  <dependency>
                  <groupId>com.oracle</groupId>
                  <artifactId>ojdbc7</artifactId>
                  <scope>provided</scope>
                  </dependency>
                  <dependency>
                  <groupId>org.apache.commons</groupId>
                  <artifactId>commons-vfs2</artifactId>
                  <scope>provided</scope>
                  </dependency>

                  <!-- Dependencies for tests -->
                  <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <scope>provided</scope>
                  </dependency>
                  <dependency>
                  <groupId>org.jmockit</groupId>
                  <artifactId>jmockit</artifactId>
                  <scope>test</scope>
                  </dependency>
                  </dependencies>





                  share|improve this answer




























                    2












                    2








                    2







                    All the common dependencies can be mentioned in the parent pom file. There mainly 4 types of dependencies that can be mentioned in a pom file.




                    1. Library Dependencies created by ourselves

                    2. Module Dependencies from our own modules

                    3. 3rd Party library Dependencies

                    4. Dependencies for tests


                    Example



                    <dependencies>
                    <!-- Library Dependencies created by ourselves -->
                    <dependency>
                    <groupId>it.myapp</groupId>
                    <artifactId>MyAppBootstrap</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>it.myapp.libs</groupId>
                    <artifactId>b2b_connecttion</artifactId>
                    </dependency>

                    <!-- Module Dependencies from our own modules-->
                    <dependency>
                    <groupId>it.myapp.mymodules</groupId>
                    <artifactId>RevenueManager</artifactId>
                    <version>${myapp.module.version}</version>
                    <classifier>classes</classifier>
                    </dependency>

                    <!-- 3rd Party Dependency -->
                    <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-rt</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc7</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-vfs2</artifactId>
                    <scope>provided</scope>
                    </dependency>

                    <!-- Dependencies for tests -->
                    <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>org.jmockit</groupId>
                    <artifactId>jmockit</artifactId>
                    <scope>test</scope>
                    </dependency>
                    </dependencies>





                    share|improve this answer















                    All the common dependencies can be mentioned in the parent pom file. There mainly 4 types of dependencies that can be mentioned in a pom file.




                    1. Library Dependencies created by ourselves

                    2. Module Dependencies from our own modules

                    3. 3rd Party library Dependencies

                    4. Dependencies for tests


                    Example



                    <dependencies>
                    <!-- Library Dependencies created by ourselves -->
                    <dependency>
                    <groupId>it.myapp</groupId>
                    <artifactId>MyAppBootstrap</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>it.myapp.libs</groupId>
                    <artifactId>b2b_connecttion</artifactId>
                    </dependency>

                    <!-- Module Dependencies from our own modules-->
                    <dependency>
                    <groupId>it.myapp.mymodules</groupId>
                    <artifactId>RevenueManager</artifactId>
                    <version>${myapp.module.version}</version>
                    <classifier>classes</classifier>
                    </dependency>

                    <!-- 3rd Party Dependency -->
                    <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-rt</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc7</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-vfs2</artifactId>
                    <scope>provided</scope>
                    </dependency>

                    <!-- Dependencies for tests -->
                    <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <scope>provided</scope>
                    </dependency>
                    <dependency>
                    <groupId>org.jmockit</groupId>
                    <artifactId>jmockit</artifactId>
                    <scope>test</scope>
                    </dependency>
                    </dependencies>






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 2 at 12:10

























                    answered Jan 2 at 12:03









                    Nipuna PriyamalNipuna Priyamal

                    302114




                    302114























                        1














                        there are two ways to achieve it -




                        1. you declare the dependencies in the parent pom in the <dependencies /> node, and each child will benefit from the dependency.


                        2. Add the dependencies in the parent pom under the <dependencyManagement /> node and in each child that requires it, add the dependency in the node. You can choose not to set the version of the dependency.



                        So for example, if you declare this in the parent pom:



                        <dependencies>
                        <dependency>
                        <groupId>org.abc</groupId>
                        <artifactId>xyz</artifactId>
                        <version>your_version</version>
                        </dependency>
                        </dependencies>
                        <dependencyManagement>
                        <dependencies>
                        <dependency>
                        <groupId>org.abc</groupId>
                        <artifactId>xyz</artifactId>
                        <version>your_version</version>
                        <scope>your_scope</scope>
                        </dependency>
                        </dependencies>
                        </dependencyManagement>





                        share|improve this answer




























                          1














                          there are two ways to achieve it -




                          1. you declare the dependencies in the parent pom in the <dependencies /> node, and each child will benefit from the dependency.


                          2. Add the dependencies in the parent pom under the <dependencyManagement /> node and in each child that requires it, add the dependency in the node. You can choose not to set the version of the dependency.



                          So for example, if you declare this in the parent pom:



                          <dependencies>
                          <dependency>
                          <groupId>org.abc</groupId>
                          <artifactId>xyz</artifactId>
                          <version>your_version</version>
                          </dependency>
                          </dependencies>
                          <dependencyManagement>
                          <dependencies>
                          <dependency>
                          <groupId>org.abc</groupId>
                          <artifactId>xyz</artifactId>
                          <version>your_version</version>
                          <scope>your_scope</scope>
                          </dependency>
                          </dependencies>
                          </dependencyManagement>





                          share|improve this answer


























                            1












                            1








                            1







                            there are two ways to achieve it -




                            1. you declare the dependencies in the parent pom in the <dependencies /> node, and each child will benefit from the dependency.


                            2. Add the dependencies in the parent pom under the <dependencyManagement /> node and in each child that requires it, add the dependency in the node. You can choose not to set the version of the dependency.



                            So for example, if you declare this in the parent pom:



                            <dependencies>
                            <dependency>
                            <groupId>org.abc</groupId>
                            <artifactId>xyz</artifactId>
                            <version>your_version</version>
                            </dependency>
                            </dependencies>
                            <dependencyManagement>
                            <dependencies>
                            <dependency>
                            <groupId>org.abc</groupId>
                            <artifactId>xyz</artifactId>
                            <version>your_version</version>
                            <scope>your_scope</scope>
                            </dependency>
                            </dependencies>
                            </dependencyManagement>





                            share|improve this answer













                            there are two ways to achieve it -




                            1. you declare the dependencies in the parent pom in the <dependencies /> node, and each child will benefit from the dependency.


                            2. Add the dependencies in the parent pom under the <dependencyManagement /> node and in each child that requires it, add the dependency in the node. You can choose not to set the version of the dependency.



                            So for example, if you declare this in the parent pom:



                            <dependencies>
                            <dependency>
                            <groupId>org.abc</groupId>
                            <artifactId>xyz</artifactId>
                            <version>your_version</version>
                            </dependency>
                            </dependencies>
                            <dependencyManagement>
                            <dependencies>
                            <dependency>
                            <groupId>org.abc</groupId>
                            <artifactId>xyz</artifactId>
                            <version>your_version</version>
                            <scope>your_scope</scope>
                            </dependency>
                            </dependencies>
                            </dependencyManagement>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 2 at 11:30









                            Sai prateekSai prateek

                            4,72463352




                            4,72463352






























                                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%2f54005418%2fwhere-to-define-test-maven-dependencies%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

                                android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                                SQL update select statement

                                'app-layout' is not a known element: how to share Component with different Modules