{"id":3606,"date":"2019-12-01T15:20:21","date_gmt":"2019-12-01T15:20:21","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3606"},"modified":"2025-04-03T12:34:07","modified_gmt":"2025-04-03T12:34:07","slug":"skipping-tests-across-multiple-child-modules-in-maven","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/skipping-tests-across-multiple-child-modules-in-maven\/","title":{"rendered":"Skipping Tests across Multiple Child Modules in Maven"},"content":{"rendered":"<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;build&gt;\r\n    &lt;plugins&gt;\r\n      &lt;plugin&gt;\r\n        &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt;\r\n        &lt;version&gt;2.9&lt;\/version&gt;\r\n        &lt;configuration&gt;\r\n          &lt;excludes&gt;\r\n            &lt;exclude&gt;${someModule.test.excludes}&lt;\/exclude&gt;\r\n          &lt;\/excludes&gt;\r\n          &lt;includes&gt;\r\n            &lt;include&gt;${someModule.test.includes}&lt;\/include&gt;\r\n          &lt;\/includes&gt;\r\n        &lt;\/configuration&gt;\r\n      &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n  &lt;\/build&gt;\r\n  &lt;properties&gt;\r\n    &lt;someModule.skip.tests&gt;false&lt;\/someModule.skip.tests&gt;\r\n    &lt;skipTests&gt;${someModule.skip.tests}&lt;\/skipTests&gt;\r\n    &lt;someModule.test.includes&gt;**\/*Test.java&lt;\/someModule.test.includes&gt;\r\n    &lt;someModule.test.excludes&gt;**\/*Test.java.bogus&lt;\/someModule.test.excludes&gt;\r\n  &lt;\/properties&gt;\r\n<\/pre>\n<p><strong>Skip all Test<\/strong><\/p>\n<pre>\r\nmvn -DsomeModule.skip.tests=true test\r\n<\/pre>\n<p><strong>Include specific Test<\/strong><\/p>\n<pre>\r\nmvn -DsomeModule.test.includes=\"**\/*IncludeTest.java\" test\r\n<\/pre>\n<p><strong>Exclude specific Test<\/strong><\/p>\n<pre>\r\nmvn -DsomeModule.test.excludes=\"**\/*ExcludeTest.java\" test\r\n<\/pre>\n<p>There would be scenarios where you need to skip few modules when building parent project because the unit test fail in child project. In such scenario we should define the surefire plugin at parent pom.xml and include and exclude the child modules for which the unit test should be executed.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;project&gt;\r\n  &#x5B;...]\r\n  &lt;build&gt;\r\n    &lt;plugins&gt;\r\n      &lt;plugin&gt;\r\n        &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt;\r\n        &lt;version&gt;2.4.2&lt;\/version&gt;\r\n        &lt;configuration&gt;\r\n          &lt;skipTests&gt;true&lt;\/skipTests&gt;\r\n        &lt;\/configuration&gt;\r\n      &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n  &lt;\/build&gt;\r\n  &#x5B;...]\r\n&lt;\/project&gt;\r\n<\/pre>\n<p>Rather than defining plugin(in our case surefire plugin), we can create a profile and define the behavior of plugins within the profile.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;project&gt;\r\n  &#x5B;...]\r\n  &lt;profiles&gt;\r\n    &lt;profile&gt;\r\n      &lt;id&gt;noTest&lt;\/id&gt;\r\n      &lt;activation&gt;\r\n        &lt;property&gt;\r\n          &lt;name&gt;noTest&lt;\/name&gt;\r\n          &lt;value&gt;true&lt;\/value&gt;\r\n        &lt;\/property&gt;\r\n      &lt;\/activation&gt;\r\n      &lt;build&gt;\r\n        &lt;plugins&gt;\r\n          &lt;plugin&gt;\r\n            &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt;\r\n            &lt;version&gt;2.4.2&lt;\/version&gt;\r\n            &lt;configuration&gt;\r\n              &lt;skipTests&gt;true&lt;\/skipTests&gt;\r\n            &lt;\/configuration&gt;\r\n          &lt;\/plugin&gt;\r\n        &lt;\/plugins&gt;\r\n      &lt;\/build&gt;\r\n    &lt;\/profile&gt;\r\n  &lt;\/profiles&gt;\r\n  &#x5B;...]\r\n&lt;\/project&gt;\r\n<\/pre>\n<p>Now lets include and exclude child modules for which unit test should be carried out<\/p>\n<p><strong>Including Unit Test<\/strong><br \/>\n<em>Only the following(ChildModule3.java) file would be included and others would be excluded<\/em><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;project&gt;\r\n  &#x5B;...]\r\n  &lt;build&gt;\r\n    &lt;plugins&gt;\r\n      &lt;plugin&gt;\r\n        &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt;\r\n        &lt;version&gt;3.0.0-M4&lt;\/version&gt;\r\n        &lt;configuration&gt;\r\n          &lt;includes&gt;\r\n            &lt;include&gt;ChildModule3.java&lt;\/include&gt;\r\n          &lt;\/includes&gt;\r\n        &lt;\/configuration&gt;\r\n      &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n  &lt;\/build&gt;\r\n  &#x5B;...]\r\n&lt;\/project&gt;\r\n<\/pre>\n<p><strong>Excluding Unit Test<\/strong><br \/>\n<em>Only the following(ChildModule1.java, ChildModule2.java) file would be excluded<\/em><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;project&gt;\r\n  &#x5B;...]\r\n  &lt;build&gt;\r\n    &lt;plugins&gt;\r\n      &lt;plugin&gt;\r\n        &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt;\r\n        &lt;version&gt;3.0.0-M4&lt;\/version&gt;\r\n        &lt;configuration&gt;\r\n          &lt;excludes&gt;\r\n            &lt;exclude&gt;**\/ChildModule1.java&lt;\/exclude&gt;\r\n            &lt;exclude&gt;**\/ChildModule2.java&lt;\/exclude&gt;\r\n          &lt;\/excludes&gt;\r\n        &lt;\/configuration&gt;\r\n      &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n  &lt;\/build&gt;\r\n  &#x5B;...]\r\n&lt;\/project&gt;\r\n<\/pre>\n<p><strong>How to activate profile in command prompt<\/strong><\/p>\n<pre>\r\n>>mvn clean install -PnoTest\r\n<\/pre>\n<p><strong>How to see list of active Profiles<\/strong><\/p>\n<pre>\r\n>>mvn help:active-profiles\r\n<\/pre>\n<p>If you want to know what version of an specific plugin you have installed you can do this:<\/p>\n<pre>\r\nmvn -Dplugin=org.codehaus.mojo:wagon-maven-plugin help:describe\r\nmvn -Dplugin=groupId:artifactId help:describe\r\nmvn help:effective-pom\r\n<\/pre>\n<p><strong>How to execute life cycle task using specific plugin<\/strong><\/p>\n<pre>\r\n>>mvn groupID:artifactID:version:goal\r\n>>mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyle\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt; &lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt; &lt;version&gt;2.9&lt;\/version&gt; &lt;configuration&gt; &lt;excludes&gt; &lt;exclude&gt;${someModule.test.excludes}&lt;\/exclude&gt; &lt;\/excludes&gt; &lt;includes&gt; &lt;include&gt;${someModule.test.includes}&lt;\/include&gt; &lt;\/includes&gt; &lt;\/configuration&gt; &lt;\/plugin&gt; &lt;\/plugins&gt; &lt;\/build&gt; &lt;properties&gt; &lt;someModule.skip.tests&gt;false&lt;\/someModule.skip.tests&gt; &lt;skipTests&gt;${someModule.skip.tests}&lt;\/skipTests&gt; &lt;someModule.test.includes&gt;**\/*Test.java&lt;\/someModule.test.includes&gt; &lt;someModule.test.excludes&gt;**\/*Test.java.bogus&lt;\/someModule.test.excludes&gt; &lt;\/properties&gt; Skip all Test mvn -DsomeModule.skip.tests=true test Include specific Test mvn -DsomeModule.test.includes=&#8221;**\/*IncludeTest.java&#8221; test Exclude specific Test mvn -DsomeModule.test.excludes=&#8221;**\/*ExcludeTest.java&#8221; test There would be scenarios where you need to skip few modules when building parent&hellip; <a href=\"https:\/\/codethataint.com\/blog\/skipping-tests-across-multiple-child-modules-in-maven\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[215],"tags":[],"class_list":["post-3606","post","type-post","status-publish","format-standard","hentry","category-maven"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=3606"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3606\/revisions"}],"predecessor-version":[{"id":5506,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3606\/revisions\/5506"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}