where to define test maven dependencies
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
add a comment |
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
1
Dependency management. And maybe you should think about a convenient parent like Spring Boot does...
– khmarbaise
Jan 2 at 11:49
add a comment |
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
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
java maven testing
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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.
add a comment |
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.
- Library Dependencies created by ourselves
- Module Dependencies from our own modules
- 3rd Party library Dependencies
- 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>
add a comment |
there are two ways to achieve it -
you declare the dependencies in the parent pom in the
<dependencies />
node, and each child will benefit from the dependency.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>
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 2 at 11:31
praneet droliapraneet drolia
2441314
2441314
add a comment |
add a comment |
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.
- Library Dependencies created by ourselves
- Module Dependencies from our own modules
- 3rd Party library Dependencies
- 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>
add a comment |
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.
- Library Dependencies created by ourselves
- Module Dependencies from our own modules
- 3rd Party library Dependencies
- 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>
add a comment |
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.
- Library Dependencies created by ourselves
- Module Dependencies from our own modules
- 3rd Party library Dependencies
- 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>
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.
- Library Dependencies created by ourselves
- Module Dependencies from our own modules
- 3rd Party library Dependencies
- 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>
edited Jan 2 at 12:10
answered Jan 2 at 12:03
Nipuna PriyamalNipuna Priyamal
302114
302114
add a comment |
add a comment |
there are two ways to achieve it -
you declare the dependencies in the parent pom in the
<dependencies />
node, and each child will benefit from the dependency.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>
add a comment |
there are two ways to achieve it -
you declare the dependencies in the parent pom in the
<dependencies />
node, and each child will benefit from the dependency.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>
add a comment |
there are two ways to achieve it -
you declare the dependencies in the parent pom in the
<dependencies />
node, and each child will benefit from the dependency.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>
there are two ways to achieve it -
you declare the dependencies in the parent pom in the
<dependencies />
node, and each child will benefit from the dependency.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>
answered Jan 2 at 11:30
Sai prateekSai prateek
4,72463352
4,72463352
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Dependency management. And maybe you should think about a convenient parent like Spring Boot does...
– khmarbaise
Jan 2 at 11:49