maven multimodule project-Update POM parent section in selected projects - maven

I am creating multimodule project using maven in eclipse.After configuring parent in that configuration tab,to add modules I have selected Add and selected the modules to be added and I have checked the 'Update POM parent section in selected projects'.But it doesnot include the parent information in the selected modules.

I was not aware that such a feature exists, but you can do it by your own, with more reliability adding those lines to your parent pom :
parent pom.xml
Here put your modules configuration
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.company.bla.bla</groupId>
<artifactId>you-parent-artifact</artifactId>
<version>1.0</version>
<modules>
<module>module-child-1</module>
<module>module-child-2</module>
</modules>
childs pom.xml
Here put you parent reference and ommit version
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.company.bla.bla</groupId>
<artifactId>you-parent-artifact</artifactId>
<version>1.0</version>
</parent>
<artifactId>child-1</artifactId>
More information here : http://www.sonatype.com/books/mvnex-book/reference/multimodule.html

Related

Maven error reguarding war files & pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.my.ssat</groupId>
<artifactId>myssatProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>myweb</artifactId>
<packaging>war</packaging>
<name>myweb</name>
</project>
Cannot access default field of properties
web.xml is missing and is set to true.
I am getting these errors whenever I create maven module in (war) format

How to create Multi-Module project on Maven?

I am trying to make a new multi-module Spring project with Maven. I have one main Pom.xml, and to other modules.
This is the main pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ev</groupId>
<artifactId>multi</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>main</module>
<module>user</module>
</modules>
And this is the module1 pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>multi</artifactId>
<groupId>org.ev</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>user</artifactId>
</project>
Where should i add the dependencies? When i put them into main pom.xml , i get an error "cant resolve pom" .
Do you have any idea about this issue? Because its very hard to create multi module project for me.
try to change main/pom.xml
<artifactId>multi</artifactId>
to
<artifactId>main</artifactId>

What tags are really required or recommended when using packaging type pom in Maven?

Once you set packaging equal to pom, do you need the groupID, artifactId and version tags and if so, what purpose do they serve? Are there any tags you should use (after all groupID is clearly intended for java so I wouldn't be surprised if there are other language or artifact type specific tags that should be used). Samples:
Simple parent pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.company</groupId>
<artifactId>project_name</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<modules>
<module>hosts</module>
</modules>
</project>
Simple child pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.company</groupId>
<artifactId>hosts</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Then sub children are various projects of many types, java, C++, angular, python, more poms.
You need all those tags.
The POMs are deployed along with the JARs, WARs etc. with their respective Maven coordinates (GroupId, ArtifactId, Version). They are resolved if anybody uses e.g. a dependency with your parent.

Spring Multi Module Project

I have to create a Spring Boot project that will have a web interactive part and a batch part a,d both with the same DB (so they share the DAOs and Services), I wonder how to do it and I guess that the best approach is to create a Multi Module Project
something like this
<modules>
<module>core</module>
<module>batchApplication</module>
<module>userApplication</module>
</modules>
But, do I have to create more than 1 pom and project ??? or I can do it in the same pom ?
You will need a parent pom which has the spring-boot as a parent, then a directory and with pom for each child project. Your parent pom will be like:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<groupId>com.barclaycard</groupId>
<artifactId>bc-alu</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Barclaycard Address LookUp</name>
<modules>
<module>bc-alu-ref</module>
<module>bc-alu-web</module>
</modules>
</project>
See here for mutil module project https://maven.apache.org/guides/mini/guide-multiple-modules.html

Maven aggregate POM version?

What is the point of having a version in a Maven aggregate (multi-module) POM? What is it used for? What would be affected if I change it?
For example:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>foobar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
…
Where is the 1.0-SNAPSHOT used? What artifacts are affected?
On a related note, what semantics does it have? Is it the version of my combined project? Or is it the version solely of the aggregation (which may remain constant through many release versions of the individual modules)?

Resources