Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass properties to maven sub-module, which does not have current module as parent

I have several maven-projects:

  • commons-lib (simple Java project)
  • user-service (Spring-Boot-driven project)
  • composite-service (Spring-Boot-driven project)
  • frontend-service (Spring-Boot- / Angular2-driven project)
  • all-services-parent (parent project building everything else)

While commons-lib is unlikely to ever be released separately, all other projects (except for the parent) might be released separately.

If the first four in the list are sub-modules of the fifth, do they have to have their parent set to parent (e.g. all-services-parent) in return?

Since I want to include commons-lib in the user- and composite-services I understand that I have to have it built first. However: each of the services above may be released separately - so which building structure is most proper for what I need?

Would it be:

-- all-services-parent
   |-- (maven sub-module) commons-lib
   |-- (maven sub-module) user-service
   |-- (maven sub-module) composite-service
   |-- (maven sub-module) frontend-service

or:

-- all-services-parent
   |-- user-service-parent
       |-- (maven sub-module) commons-lib
       |-- (maven sub-module) user-service
   |-- composite-service-parent
       |-- (maven sub-module) commons-lib
       |-- (maven sub-module) composite-service
   |-- frontend-service

The second building structure would allow me to build all the JARs by calling "mvn clean install" on all-services-parent while still being able to build separate projects properly by calling "mvn clean install" on the corresponding parent, but is it really how it's done?

In my current setup I am trying to use the first building structure, but since e.g. composite-service has "spring-boot-starter-parent" set as its parent, I cannot access the properties or anything from the "all-services-parent"-module.

I read into Maven parent pom vs modules pom (a question that looked promising at first), but it did not apply to my case as much as I would like it to.

like image 469
Igor Avatar asked Mar 22 '18 07:03

Igor


People also ask

How to exclude module from Maven build?

With Maven 3.2. 1, you can now use -pl ! <module_name>,! <module_name> to exclude certain modules from the reactor build.

What is Project Basedir in Maven?

project. basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.

What are maven properties?

Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example: In your case you have defined properties as version of java. Now this property( java.


1 Answers

Try to import the spring boot parent and not inherit from it like this:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.5.9.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
       </dependencies>
</dependencyManagement>
like image 115
Sándor Juhos Avatar answered Oct 30 '22 02:10

Sándor Juhos