{"id":257,"date":"2020-10-21T23:16:27","date_gmt":"2020-10-21T23:16:27","guid":{"rendered":"https:\/\/www.oreineke.dev\/?p=257"},"modified":"2024-09-30T11:49:45","modified_gmt":"2024-09-30T11:49:45","slug":"spring-boot-projekts-as-maven-sub-modules","status":"publish","type":"post","link":"https:\/\/www.oreineke.dev\/?p=257","title":{"rendered":"Spring Boot Projects as Maven Sub-Modules"},"content":{"rendered":"\n<p>The easiest ways to setup a <a href=\"https:\/\/spring.io\/\">Spring Boot<\/a> project with <a href=\"https:\/\/maven.apache.org\/\">Maven <\/a>is to define <code>spring-boot-starter-parent<\/code> as the project&#8217;s parent in you POM file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; highlight: [4]; title: ; notranslate\" title=\"\">\n&lt;project ...&gt;\n&lt;parent&gt;\n  &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n  &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n  &lt;version&gt;2.3.4.RELEASE&lt;\/version&gt;\n &lt;\/parent&gt;\n...\n<\/pre><\/div>\n\n\n<p>This way,  you will inherit some useful dependencies and other definitions.<\/p>\n\n\n\n<p>But there are situations when you need to use a different parent, for example if your Spring Boot project is supposed to be a sub-module in a larger project.<\/p>\n\n\n\n<p>In this case, you can still import the above mentioned dependencies by adding <code>spring-boot-dependencies<\/code> as a dependency in the <code>&lt;dependencyManagement&gt;<\/code> section of your POM file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; highlight: [1,5,11]; title: ; notranslate\" title=\"\">\n&lt;dependencyManagement&gt;\n  &lt;dependencies&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-dependencies&lt;\/artifactId&gt;\n      &lt;version&gt;2.3.4.RELEASE&lt;\/version&gt;\n      &lt;type&gt;pom&lt;\/type&gt;\n      &lt;scope&gt;import&lt;\/scope&gt;\n    &lt;\/dependency&gt;\n  &lt;\/dependencies&gt;\n&lt;\/dependencyManagement&gt;\n<\/pre><\/div>\n\n\n<p>But you will find that your integration tests, usually managed by the Maven <a href=\"https:\/\/maven.apache.org\/surefire\/maven-failsafe-plugin\/\">Failsafe plugin<\/a>, will now fail with an error:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nUnable to find a @SpringBootConfiguration\n<\/pre><\/div>\n\n\n<p>To resolve this, you need to add the following <code>&lt;classesDirectory&gt;<\/code> configuration to the Failsafe plugin definition in your POM file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; highlight: [14]; title: ; notranslate\" title=\"\">\n&lt;plugin&gt;\n  &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n  &lt;artifactId&gt;maven-failsafe-plugin&lt;\/artifactId&gt;\n  &lt;version&gt;2.22.2&lt;\/version&gt;\n  &lt;executions&gt;\n    &lt;execution&gt;\n      &lt;goals&gt;\n        &lt;goal&gt;integration-test&lt;\/goal&gt;\n           &lt;goal&gt;verify&lt;\/goal&gt;\n        &lt;\/goals&gt;\n    &lt;\/execution&gt;\n &lt;\/executions&gt;\n &lt;configuration&gt;\n   &lt;classesDirectory&gt;${project.build.outputDirectory}&lt;\/classesDirectory&gt;\n &lt;\/configuration&gt;\n&lt;\/plugin&gt;\n\n<\/pre><\/div>\n\n\n<p>You can confirm that this definition is in fact part of the <code>spring-boot-starter-parent<\/code>&#8216;s POM by <a href=\"https:\/\/repo1.maven.org\/maven2\/org\/springframework\/boot\/spring-boot-starter-parent\/2.3.4.RELEASE\/spring-boot-starter-parent-2.3.4.RELEASE.pom\">looking into it<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The easiest ways to setup a Spring Boot project with Maven is to define spring-boot-starter-parent as the project&#8217;s parent in you POM file: This way, you will inherit some useful dependencies and other definitions. But there are situations when you need to use a different parent, for example if your Spring Boot project is supposed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","osh_disable_topbar_sticky":"default","osh_disable_header_sticky":"default","osh_sticky_header_style":"default","osh_sticky_header_effect":"","osh_custom_sticky_logo":0,"osh_custom_retina_sticky_logo":0,"osh_custom_sticky_logo_height":0,"osh_background_color":"","osh_links_color":"","osh_links_hover_color":"","osh_links_active_color":"","osh_links_bg_color":"","osh_links_hover_bg_color":"","osh_links_active_bg_color":"","osh_menu_social_links_color":"","osh_menu_social_hover_links_color":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[9,10],"tags":[],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-java","category-spring","entry"],"categories_names":["Java","Spring"],"post_class":[["post-257","post","type-post","status-publish","format-standard","hentry","category-java","category-spring","entry"]],"author_avatar":["<img alt='' src='https:\/\/secure.gravatar.com\/avatar\/a57dd6e6879c288f9d7c2e6b98faed481a067e5e155cc409952ac7e08d656a28?s=96&#038;d=mm&#038;r=g' srcset='https:\/\/secure.gravatar.com\/avatar\/a57dd6e6879c288f9d7c2e6b98faed481a067e5e155cc409952ac7e08d656a28?s=192&#038;d=mm&#038;r=g 2x' class='avatar avatar-96 photo' height='96' width='96' loading='lazy' decoding='async'\/>"],"featured_video":null,"_links":{"self":[{"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=257"}],"version-history":[{"count":7,"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions\/295"}],"wp:attachment":[{"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oreineke.dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}