7

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.

3 Answers 3

3

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>
2
  • But what would I do thereafter? Should I be always setting the module-parent as the parent in a sub-module's pom.xml?
    – Igor
    Commented Mar 22, 2018 at 7:25
  • It seems this suggestion is the closest to solving my problem. I decided to go with the first build-structure and using profiles, that are active by default, but also allow to build individual module groups. I still have no idea how to pass properties to child-modules, but I circumvented that need. Also it seems to not be a good idea to use variables in e.g. the version- or group-tag in a pom.xml, because that would unnecessarily tie modules together.
    – Igor
    Commented Mar 25, 2018 at 17:12
0

Parent module properties file can access by sub modules but sub modules properties file cannot access to other sub modules.
or
You need to do separate properties file for each sub modules.

1
  • That I know (sub-modules cannot access the properties of other sub-modules). In my case I am just not sure whether I should be trying to set up the first building structure or the second one (see the pre-tags in my post).
    – Igor
    Commented Mar 22, 2018 at 7:27
-1

Add your sub modules like this in your pom.xml file and give its absolute path.
This should be work

<modules>
        <module>../TestWeb</module>
        <module>../TestBusiness</module>
        <module>../MsgScheduler</module>
        <module>../Connector</module>                   
</modules>
1
  • That I have already done - I did read the manual. It's just that I was not able to inherit properties, because I thought I could not adjust the parent to anything else than the spring-boot-starter-parent, but apparently I can (see Sandor Juhos' reply).
    – Igor
    Commented Mar 22, 2018 at 8:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.