Can a parent maven project include a module at the same directory level

I work in an installed code base with an existing standalone pom.xml.

It is assumed that the child project is called "hive" in the subdirectory with the parent. Note: hive / pom.xml already exists and it works just fine on its own.

So, in the parent pom.xml, I added:

<modules> <module>hive</module> </modules> 

The problem is that I basically lose the ability to create a deployed jar from the parent project.

 stephenb@gondolin :/shared/git2/etl$ mvn package assembly:single [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [ERROR] FATAL ERROR [INFO] ------------------------------------------------------------------------ [INFO] Error building POM (may not be this project POM). Project ID: com.myco.etl:etl POM Location: /shared/git2/etl/pom.xml Validation Messages: [0] Packaging 'jar' is invalid. Aggregator projects require 'pom' as packaging. Reason: Failed to validate POM for project com.myco.etl:etl at /shared/git2/etl/pom.xml [INFO] ------------------------------------------------------------------------ [INFO] Trace org.apache.maven.reactor.MavenExecutionException: Failed to validate POM for project com.myco.etl:etl at /shared/git2/etl/pom.xml at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 

It seems that maven wants me to create a parent pom that basically does nothing but define dependency modules.

Well, I can create a new pom.xml. But what I cannot do is drag and drop existing project files into a new subdirectory.

Is there any way around this? For instance. defining a submodule that lives on the same level (not subdir)? Or any other way to work with an existing dir structure?

thanks

Subsequent actions: based on the input that the module may just be a file in the local directory, I created another zhuk that calls the source one. The original was renamed to pommod.xml, and the new one shown below is called 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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.myco.etl</groupId> <artifactId>etl</artifactId> <name> ETL Helpers</name> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>appminer</module> <module>pommod.xml</module> </modules> 

I ran the mvn compile package. But still getting the same error:

 Project ID: com.myco:app_miner POM Location: /shared/git2/etl/mycopom.xml Validation Messages: [0] Packaging 'jar' is invalid. Aggregator projects require 'pom' as packaging. Reason: Failed to validate POM for project com.myco:app_miner at /shared/git2/etl/myco/pom.xml 
+6
source share
2 answers

To answer the question in the header of this post:

Yes, Maven can include a parent and a module at the same directory level. I feel that I must first explain that a parent can have children and modules. Children and modules are not the same thing:

  • A child relation is defined through parent in the child POM. If your parent is in the repo, then this. If your parent is on the file system, you need to play with parent.relativePath so that it can be found in the same folder
  • A module is defined through modules in the parent POM. The module usually contains the name of the folder, and the POM file is implied (for example, <module>mod</module> equivalent to <module>mod/pom.xml</module> ). Therefore, the module in the same folder will be <module>pom1.xml</module> or something else. (I called the POM module of the pom1.xml file in this example, assuming that pom.xml has already taken the parent - let's see what mess we are in)

Let me quickly give you an example where children and modules differ from each other: you can have a POM to create an application for each of your teams. Each of your teams can have web applications and backend applications. You can have parent POMs for web applications and backend applications. Thus, some backend application will be a child of the POM for backend applications, being a module of the team that works on it.


It seems to me that this is about packaging. Parent POM ( pom packaging) is usually just a bunch of metadata and nothing more. If you want this to be something else, you can still connect plugins to the stages of the life cycle. You can even run packaging modules and apply the results to an artifact.


I did not understand why hive cannot be a child (own folder, own POM in this folder), beautifully on the same level as the parent, as Maven suggested. But it sounded like you could have some kind of project in any other directory, depending on the jar artifact in hive and turning it into whatever assembly you want. So hive will depend on the build project (say hive-assembly ). It comes to my next point ...


The fact that Maven really allows you to have parent and child objects in the same folder is not a good argument for this. It is only a matter of time for some part of Maven or one of its plugins will work against you. Maven is a " configuration agreement ", live it!

+10
source

This problem can be solved with maven. Aggregating projects instead of Project Inheritance .

+2
source

Source: https://habr.com/ru/post/943488/


All Articles