building multi module projects in jenkins

2,173 views
Skip to first unread message

paul b

unread,
Mar 10, 2017, 11:53:17 AM3/10/17
to Jenkins Users

I have several projects that are multi module projects that are like the following

 

Project1

+-module1

  +-pom.xml

+-module2

  +-pom.xml

 

Each project is configuration controlled in git as their own project

 

Now, I have created a parent project with the following flat structure.  This is because I would like to keep each project with its own git project.  That seems sensible for me???

 

Parent

+-pom.xml

 

Project1

+-module1

  +-pom.xml

+-module2

  +-pom.xml

 

Project2

+-module1

  +-pom.xml

+-module2

  +-pom.xml

 

 

The parent pom references each project like the following

 

  <modules>

    <module>../project1</module>

    <module>../project2</module>

  </modules>

 

This is fine as per maven documentation and all works ok locally but when I build this from Jenkins I run into issues.  This is because Jenkins cant find the pom file for each project.  Basically this is down to the flat directory structure!  Is there any way in Jenkins that I can get over this issue?  

 

David Karr

unread,
Mar 10, 2017, 1:43:06 PM3/10/17
to Jenkins Users
On Fri, Mar 10, 2017 at 8:53 AM, paul b <pbla...@gmail.com> wrote:
> I have several projects that are multi module projects that are like the
> following
>
> Project1
> +-module1
> +-pom.xml
> +-module2
> +-pom.xml
>
> Each project is configuration controlled in git as their own project
>
> Now, I have created a parent project with the following flat structure.
> This is because I would like to keep each project with its own git project.
> That seems sensible for me???

A basic rule for deciding where you should separate things into their
own git repository is whether the two things need to be built
together. If they need to be built together, then keep them in the
same repository. The structure you've defined is not "sensible".

> Parent
> +-pom.xml
> Project1
> +-module1
> +-pom.xml
> +-module2
> +-pom.xml
>
> Project2
> +-module1
> +-pom.xml
> +-module2
> +-pom.xml
>
> The parent pom references each project like the following
>
> <modules>
> <module>../project1</module>
> <module>../project2</module>
> </modules>
>
> This is fine as per maven documentation and all works ok locally but when I
> build this from Jenkins I run into issues. This is because Jenkins cant
> find the pom file for each project. Basically this is down to the flat
> directory structure! Is there any way in Jenkins that I can get over this
> issue?

Fix the problem in your repository structure, not in Jenkins.

paul b

unread,
Mar 11, 2017, 6:04:26 AM3/11/17
to Jenkins Users
Thanks David for your response.  I appreciate your comments.  So, I would like to build the project from the parent so could do the following.  Doing this gives me the ability to build all projects from the parent and to build indivdual projects too!  Which is what I want to achieve from jenkins.  Although from the git repository point I dont want the parent to have the responsibility of all the projects.  I want each individual project to have their own git repo.  That makes sense to me.  I would like to know if there are any possible solutions from a git point?  It doesnt seem like this solution is scalable?    

Parent

+-pom.xml

+-Project1

  +-module1

    +-pom.xml

  +-module2

    +-pom.xml

+-Project2

  +-module1

    +-pom.xml

  +-module2

    +-pom.xml

Stephen Connolly

unread,
Mar 11, 2017, 9:08:35 AM3/11/17
to jenkins...@googlegroups.com
The question you need to ask when splitting among repositories is about what the release cycle is.

If things *always* _have to_ be released together, then they should be in the same repo.

If things *sometimes* (at least twice) _just might_ be released independently (i.e. Where one gets an additional release from the other), then they must be in separate repos.

Life is simpler if you do not have -SNAPSHOT dependencies across repos.

Now having said all that, you can set up your parent to pull the children into its reactor *if they are present* by using profiles with file based activation to declare the modules... it's not pretty, but it does work. Hopefully for Maven 5 we can have a better solution.

My normal approach is to instead create a "throwaway aggregator only pom" that pulls in everything and build that. The aggregator pom could be created on the fly before you build and would reference the parent and all the child modules. That removes the pain of profiles in the parent and sets up the reactor for you such that everything is discovered by Maven

HTH


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5d99a764-5c68-452b-b7fc-a6f3a43640ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

paul b

unread,
Mar 12, 2017, 3:06:43 PM3/12/17
to Jenkins Users
Thanks Stephen for your reply.  So, to answer your questions.

1. The parent can be released independently.  I still want the projects to have their own repo and can be built independently .
2. I intend to have SNAPSHOTs across repos which some of them are dependent on others!

I agree that the parent(aggregator) pom sounds a good idea.  I just need common stuff in that and something to pull in the child modules.  Although, not sure at this point whether I may need to add to the aggregator pom in the future... So, I guess the question keeps coming up about how to config control the aggregator!?!  I have been reading about git sub modules and from what I can see I might have to convert the existing .git projects to be sub modules!?!  Not sure if this is right way to go though.  Why is this so hard!!!   
Reply all
Reply to author
Forward
0 new messages