Creating multi module Maven Projects in Eclipse - eclipse

Trying to create a multi module maven project in eclipse.
Parent 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>parent</groupId>
<artifactId>proj1</artifactId>
<version>${myversion}</version>
<packaging>pom</packaging>
<properties>
<myversion>1.0.0</myversion>
</properties>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
</project>
Child-Module 1 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>proj1</artifactId>
<groupId>parent</groupId>
<version>${myversion}</version>
</parent>
<groupId>parent</groupId>
<artifactId>child1</artifactId>
<version>${myversion}</version>
</project>
Child Module 2 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>proj1</artifactId>
<groupId>parent</groupId>
<version>${myversion}</version>
</parent>
<groupId>parent</groupId>
<artifactId>child2</artifactId>
<version>${myversion}</version>
<dependencies>
<dependency>
<groupId>parent</groupId>
<artifactId>child1</artifactId>
<version>${myversion}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
If I use mvn clean install on command line from the parent folder I can build find. All the projects are build successfully.
But in eclipse I keep getting an error for Child Module 2 pom.xml
Description Resource Path Location Type
parent:child1:1.0.0:jar Missing:
----------
1) parent:proj1:pom:${myversion}
----------
1 required artifact is missing.
for artifact:
parent:proj1:pom:${myversion}
from the specified remote repositories:
central (http://repo1.maven.org/maven2, releases=true, snapshots=false)
pom.xml /child2 line 1 Maven Problem
I need to achieve 2 things
1. have a maven property define the version in the parent pom file.
2. use this property to define the version in all the child modules.
What should I do? I am stuck. Please help.
I am using Eclipse Galileo with m2Eclipse

This can't work, you can't get the version of the parent to use from the parent (and actually, properties don't get substituted in the parent element, see MNG-624). So you need to hard code the version and your parent POM should be:
<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>parent</groupId>
<artifactId>proj1</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
</project>
And in your child POM 1. you need to hardcode the version in /project/parent/version 2. you don't need to specify the <version> (you inherit it) 3. use the ${project.version} property in dependencies.
<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>
<artifactId>proj1</artifactId>
<groupId>parent</groupId>
<version>1.0.0</version>
</parent>
<groupId>parent</groupId>
<artifactId>child2</artifactId>
<!--version>${myversion}</version--> <!-- Inherited -->
<dependencies>
<dependency>
<groupId>parent</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version> <!-- use the built-in property here -->
<!--type>jar</type--> <!-- This is a default, you can omit it -->
<!--scope>compile</scope--> <!-- This is a default, you can omit it -->
</dependency>
</dependencies>
</project>
Versionless parent elements will be supported in Maven 3.1.
See also
Missing artifact error in Maven
Eliminate Maven POM Redundancy
Maven 3 - Worth it???

Related

Non-resolvable parent POM for " ":0.0.1-SNAPSHOT: Could not find artifact " ":pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM

As the title describes it is an "Non-resolvable parent POM for Could not find artifact and 'parent.relativePath' points at wrong local POM" problem, found often on stackoverflow, but i haven't found a matching one. So here's my problem description
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.salamoneleonardo:facturacion-rest:0.0.1-SNAPSHOT: Could not find artifact com.salamoneleonardo:ventas:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 15, column 13
[FATAL] Non-resolvable parent POM for com.salamoneleonardo:facturacion-logic:0.0.1-SNAPSHOT: Could not find artifact com.salamoneleonardo:ventas:pom:0.0.1-SNAPSHOT and 'parent.relativeyec - copia\ventas\proyecto-ventas\facturacion-persistencia\src\pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.salamoneleonardo:facturacion-persistencia:0.0.1-SNAPSHOT: Could not find artifact com.salamoneleonardo:ventas:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 15, column 13
I leave the POM below
Pom main
<modelVersion>4.0.0</modelVersion>
<groupId>com.salamoneleonardo</groupId>
<artifactId>ventas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ventas</name>
<url>https://start.spring.io</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>facturacion-rest/src</module>
<module>facturacion-logic/src</module>
<module>facturacion-persistencia/src</module>
</modules>
Pom rest
<modelVersion>4.0.0</modelVersion>
<artifactId>facturacion-rest</artifactId>
<name>facturacion-rest</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.salamoneleonardo</groupId>
<artifactId>ventas</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependency>
<groupId>com.salamoneleonardo</groupId>
<artifactId>facturacion-logic</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
POM logic
<modelVersion>4.0.0</modelVersion>
<artifactId>facturacion-logic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>facturacion-logic</name>
<parent>
<groupId>com.salamoneleonardo</groupId>
<artifactId>ventas</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.salamoneleonardo</groupId>
<artifactId>facturacion-persistencia</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
POM persistence
<modelVersion>4.0.0</modelVersion>
<artifactId>facturacion-persistencia</artifactId>
<name>facturacion-persistencia</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>11</java.version>
</properties>
<parent>
<groupId>com.salamoneleonardo</groupId>
<artifactId>ventas</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

Maven module jar missing

I've got a multi-modules maven project and I'm trying to add a module to my project. I know a lot of questions have been asked but it didn't solved my problem. When I deploy my project, the .jar of my new module is not registered whereas my others modules are working properly.
I've added the new module in the pom of my parent module in my dependency management:
<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.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.33-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>base</module>
<module>mynewmodule</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.project</groupId>
<artifactId>mynewmodule</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
About the pom of the new module, I've specified the packaging to jar:
<?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>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.33-SNAPSHOT</version>
</parent>
<artifactId>mynewmodule</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>base</artifactId>
</dependency>
</dependencies>
</project>
I've also done a maven build project.
I don't understand then why when I deploy my project with Jenkins, the jar of my new module is missing. Have I missed something?

Scala-Maven project on Eclipse

I am trying to use this Scala project.
The project contains maven dependencies so I have created a pom.xml and then I have imported the project as a maven project in eclipse.
In order to test the project I tried to add a Scala class, but I'm surprised that I can't.
this is my 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>com.group-name</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.12.6</version>
</dependency>
<dependency>
<groupId>org.opencypher</groupId>
<artifactId>spark-cypher</artifactId>
<version>0.1.5</version>
</dependency>
</dependencies>
</project>
i imported it to eclipse as a maven project then i build the maven project.
My questions are:
1) is my approach right ?
2) if 1) is right then how can I use this Scala project with maven ??
In order to import a Scala Maven Project on eclipse, you need to :
• install Scala plugin for eclipse (HELP>ECLIPS MARKETPLACE>”search for Scala ide”)
• Install Maven Integration for Scala IDE(HELP>INSTALL NEW SOFTWARE>”search for http://alchim31.free.fr/m2e-scala/update-site/”)
• Import project as Existing Maven Projects
Try the below POM
<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.group-name</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.12.6</version>
</dependency>
<dependency>
<groupId>org.opencypher</groupId>
<artifactId>spark-cypher</artifactId>
<version>0.1.5</version>
</dependency>
</dependencies>
</project>

Problems with Pom.xml

I hope you guys can help me out.
I want to make a simple webLogin (Maven project) so far my code works. Now to make a build and deploy it i had to look into poms and i really tried but i don't know what i am doing wrong. Maybe someone knows how to do it right
My project tree:
pom.xml(project)
<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.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LoginTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
pom.xml(app)
<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>src.main.java</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>/pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<exclude-ui>false</exclude-ui>
<api.ctx.root>/rest</api.ctx.root>
<ui.ctx.root>/webui</ui.ctx.root>
</properties>
</profile>
</profiles>
</project>
pom.xml(rest)
<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>src.main.java</groupId>
<artifactId>rest</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>src.main.java.app</groupId>
<artifactId>Login.java</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
<packagingExcludes>WEB-INF/lib/*intf*.jar,WEB-INF/lib/*shared*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml(webui)
<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>src.main.java</groupId>
<artifactId>webui</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>LoginTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<exclude-ui>false</exclude-ui>
<api.ctx.root>/rest</api.ctx.root>
<ui.ctx.root>/webui</ui.ctx.root>
</properties>
</profile>
</profiles>
</project>
This is what i get right now and im sure this will not be the last ERROR i get..
[ERROR] Non-resolvable parent POM for src.main.java:app:1.0.0: Could not find artifact org.apache.maven:LoginTest:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 12, column 10 -> [Help 2]
Maybe someone can help me thanks in advance
Your project structure seems to be broken. You usually have one pom per project, and especially you should not have pom files in the src/main/java. If you want to define modules (subprojects) they need to have their own inner structure (as every Maven project).

build maven downstream projects in eclipse

When Jenkins builds a project it automatically builds all downstream projects. That is, all projects that are dependent on the project beiing built. Is it possible to replicate that behaviour in Eclipse with m2eclipse?
You mean modules?
check this link:
This is the basic idea:
<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/maven4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>exampleApp</name>
<packaging>pom</packaging>
<modules>
<module>dependency1</module>
<module>dependency12</module>
<module>mainProject</module>
</modules>
</project>