How to avoid DuplicateProjectException exception - java

Hy,
I have a multi-module maven project. I use to create these projects with Talend studion. I try to create a CI/CD build flow in MS Azure devops based on the Talend studion generated code. The generated maven poms are look like:
Parent pom:
<Modules>
<Module>Project A<Module>
<Module>Project B<Module>
</Modules>
Module A pom:
// no reference to other module
Module B pom:
<Modules>
<Module>Project A<Module>
<Module>pom-control-bundle.xml<Module>
<Module>pom-feature.xml<Module>
</Modules>
When I try to queue with MS Azure devops, I encounter this error message:
DuplicateProjectException : Project A is duplicated in the reactor #
Any idea, what should I configure to solve this problem?

I just recognised no need to build the whole project but the subproject. In Talend, you create jobs, services, route, and they are separated java projects. If they will publish somewhere you need to upload the job, service, route, not the whole project. So, I need to run the build flow on the job, service, route. So I need to point on the job's -also service, route, etc...- pom.xml not the parent project's pom.xml.
So you can avoid this error above, if you build the modules separate.

Related

Update version of Maven modules in one place only

I have a Maven project with 2 modules. I want the modules to inherit the version of that project, without defining it as a parent in the POM file of any submodules (the reason behind that is that the modules already have parents). What would be the best way to achieve that?
Importing the version from a properties file doesn't work because maven expects a constant value as a project version, not an expression. Maven plugins such as the version maven plugin or the maven release plugin are not solutions to my problem because I need something that would work in an IDE (I have to use Eclipse for packaging the projects, not my call).
Edit
To clarify things (apologies if my original post was not clear enough)
Main Project POM file
...
<groupId>org.mygroup</groupId>
<artifactId>parentproject</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
...
Module POM file example
...
<groupId>org.mygroup</groupId>
<artifactId>module1</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<!-- Some parent that's NOT the main project, e.g. Spring Boot -->
</parent>
...
What I want is a solution that would allow me to set the version only ONCE (e.g. in the main project POM file) and having every module of that project to "inherit" that version.
You should probably set the parent back to your actual parent project. Version numbers between modules can be simultanuously updated using mvn versions:set. If you need the version number for cross-module dependencies, use ${project.version}. If you want to embed another Maven configuration file for its dependencies, consider using a Bill-of-material (BOM): https://stackoverflow.com/a/14876651 . Hope things brings you to your answer!
I really can't think of any Maven facility that fit 100% your necessities. Event if you could set the parentproject as an actual parent on each submodule, you'd need to specify its version in the parent declaration, so...
But I think of a trick to do the job through an authomatism, so that every time the parent version is changed, it will be automatically propagated to each submodule. It can be done like this:
Program a plugin in the parent project that writes the version id on each of its modules' pom files (for example, through an XSL transformation with the xml-maven-plugin).
Then, link this plugin to the package phase, so that every time the parent is build, the versions gets propagated to the submodules.
You only will have to refresh the submodules projects in Eclipse to make Eclipse be aware of the changes.
But if you don't want to refresh manually, there is still another alternative - fully based on Eclipse:
Make an Ant script to perform the copy-version-to-all-module-poms task. And, instead of calling it from a Maven phase, program an Eclipse builder to call it and, within this builder, program also a refresh of the specific modules. So, every time you execute a build of your project, it will copy its version to the submodules and make Eclipse be aware of this change.

Maven how to automate installation of dependencies?

I have 3 projects, A->B->C in that dependency order. Currently everytime I make a change to B or C I have to go to the directory and do a mvn clean install in order to install it into the local repository. It is troublesome if I have to do this every time the projects updates.
How can I do it such that every time I do a mvn clean package on A, it will automatically build and install my dependent projects B and C into the local repository?
Create a parent project for all your projects A,B,C and then add all your child project on the parent pom.xml file something like this
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
</modules>
Its called maven multi module project mentioned by #khmarbaise
Here are some example for this
How do I create a multi-module project in Eclipse?
Maven Multi module tutorial
Guide to Working with Multiple Modules
By use of multi module project you will get plenty of benefits like
Anytime you can add any new project with all of the current project
Separation of project is good for code cleanup
You can build Single project or You can build all project in one go.
Duplicacy of jar can be easily ignore .
Maven take care of the build order for you.
One single Jenkins job to build everything.
Plenty of other benefits.But remember if there will some pros then cons also there,its totally now what you want to use .
You can follow the solution I provided to the question Maven 2 Projects, since it is the pattern I usually use when building project with a certain complexity.
Summarizing you would have to create a main Maven project which has three submodules, say master, platform and parent.
The main project has simply the order in which the other projects will be evaluated by Maven
The master pom contains the list of project to be built and their order (aka Reactor order)
The platform pom contains all information about your platform, like JDK version, maven plugin versions, encoding and so on.
The parent pom has the platform pom as a parent and contains all global GAV information about the dependencies you are going to use in your project (Spring, CXF, junit, log4j etc.)

How to setup Jenkins build with two separate repositories (poms)?

My project structure looks as follows:
Core
pom.xml
Project A
pom.xml
Project B
pom.xml
Core, Project A, Project B are separate git repositories. I need this structure because all of my Projects should use the same core settings (and when I have to change something in the core, all Projects are updated without having troubles).
I haved added the following dependency to the Project (Project A + Project B) pom:
<!-- Core -->
<dependency>
<groupId>my-group</groupId>
<artifactId>my-core</artifactId>
<version>${my-core.version}</version>
</dependency>
In eclipse on my local machine it works like a charm. The project finds the core and i am able to run all of my selenium tests.
Now I want to setup jenkins and one jobs should contain Project A + Core, another job Project B + Core - but I have no idea how to do that. I have already searched for some solutions, but I dont want to setup a Nexus for example. So is there a easy way to include my core + project in jenkins?
Looking forward to your answers!
You can use Multiple SCMs Plugin to retrieve all repositories into job's workspace and then:
Build and install core project using maven's install lifecycle (so, my-core becomes available in local maven repository on Jenkins machine).
Build Project A
Build Project B
In the SCM section of the Jenkins job configuration screen, choose 'Multiple SCMs'. You'll then see a drop-down list of the available SCM plugins which can be configured similar to the way build steps are configured for a freestyle job. When chosen, each SCM plugin will present its normal set of configuration options.
Make sure each SCM checkout is done in a separate sub-directory of the workspace to avoid conflicts between the SCM providers. If using Mercurial, this option is hidden in the 'Advanced' section, so don't forget to configure it.
If changing the SCM provider for an existing job, I recommend wiping out the workspace.

Two Spring MVC / Maven modules in one project

I try to make a JavaEE application with 2 and more Spring MVC modules. Before I had WebSuite module, that have Web and DB modules
<modules>
<module>../UBDB</module>
<module>../UBWeb</module>
</modules>
In the DB module are all classes that work with database; in the web module - Spring MVC for views.
But now I need to re-organize my project. I need Maven managed modules, that will consist of different business logic. For example: I need one module that will have controllers and views to manage accounts, another module to create orders, another module for blog etc. (something like CMS). All of these modules need to be on Spring MVC.
But how do I need organize my pom.xml files to make it?
For a webapp, we always loose our time with maven module to think we have a nice separation... that's useless.
Create an account-parent with
Account model
used by Account dao
used by Account service
used by Account controller
Do the same for all the group you wanna do.
Then create a single module app : MyWebApp. It contains just config, properties and add all the controllers in runtime.
You will loose your time while releasing modules, updating dependencies, ...
I worked this way untill last year.
So, sorry for late answer, but I found solution.
I have one module suite - that I use to get all modules in my project
<modules>
<module>../news</module>
<module>../blog</module>
<module>../suite</module>
</modules>
Also it have <packaging>pom</packaging> property
Description news and blog are quite similar
We can package it like jar files.
So, as I sad, I whanted to have some CMS system. How it works. I copy all nessesary modules to some directory. For example I will create site with news and blog module. So I copy there suite module, news and blog module(news and blog module are Spring MVC apps. Suite just pom.xml file). Then I create new directory (site module). In pom.xml of it I set
<packaging>war</packaging>
then in suite module I ad line for it.
<module>../site</module>
So I have 3 SpringMVc applications. 2 of them (news, blog are my modules, that I can set to different projects. Site - new module. It will be deploeed like Jar file This module different for different projects) and suite just to get all modules together.
And then mvn clean package.
Hope It will help for someone

Advise on setting up maven for multiple projects

I was looking at some open source projects and noticed they have a setup like:
/app1/pom.xml
/app1/app1-mod1/pom.xml
/app1/app1-mod2/pom.xml
/app1/app1-mod3/pom.xml
So there is a master pom, and then all the modules have pom.xml also.
So in my situation I have the following:
1. spring mvc application
2. spring mvc application
3. shared model/db layer
So I guess I should be following the multiple pom.xml setup?
If yes, how will I get #3 to build before #2 and #1.
Should I be dropping down to ant to perform the actual build?
Any tutorials that you guys know of to walk me through this process?
I'm coding in IntelliJ.
The Maven reactor will build the modules in an appropriate order, you can tell it what you think the best way is by sorting them how you want.
I have a similar project setup like this:
<artifactId>root</artifactId>
<packaging>pom</packaging>
<name>Root</name>
<modules>
<module>event</module>
<module>admin</module>
<module>public</module>
</modules>
This is then used as a parent by the other modules. The event library is used in both the admin and public webapp modules. In the webapp modules define something like this:
<dependencies>
<!-- Events -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>event</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
A mvn install from the root works beautifully.
Maven will calculated the dependencies by itself it you setup your POMs so that
module #1 and #2 both depend on #3 maven will build #3 first without any additional configuration required.
The layout you use (multi module) is also required for the release plugin.
See also A Multi-module Project

Categories

Resources