Maven `help: efficient-pom`, creating for only one project, not all projects

I want to create an effective pom for all subprojects in a multi-module assembly.

The help:effective-pom documentation here claims

It will iterate over all projects in the current build session, printing an effective POM for each

I run mvn help:effective-pom in the root directory of this maven project and it generates only for the root and not for subprojects,

Why effective pom is not created for all projects. Note. I have another real-world maven project where mvn help:effective-pom correctly generates a <projects> with a nested <project> for each submodule. I'm not sure why it is not working for this maven project

Here is the efficient pom generation

 <!-- ====================================================================== --> <!-- --> <!-- Generated by Maven Help Plugin on 2017-11-12T09:56:26 --> <!-- See: http://maven.apache.org/plugins/maven-help-plugin/ --> <!-- --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- --> <!-- Effective POM for project --> <!-- 'org.gradle.test.performance:project:pom:1.0' --> <!-- --> <!-- ====================================================================== --> <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.gradle.test.performance</groupId> <artifactId>project</artifactId> <version>1.0</version> <packaging>pom</packaging> <modules> <module>project0</module> <module>project1</module> <module>project2</module> <module>project3</module> <module>project4</module> <module>project5</module> <module>project6</module> <module>project7</module> <module>project8</module> <module>project9</module> </modules> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </pluginRepository> </pluginRepositories> <build> <sourceDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\src\main\java</sourceDirectory> <scriptSourceDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\src\main\scripts</scriptSourceDirectory> <testSourceDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\src\test\java</testSourceDirectory> <outputDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target\classes</outputDirectory> <testOutputDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target\test-classes</testOutputDirectory> <resources> <resource> <directory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\src\main\resources</directory> </resource> </resources> <testResources> <testResource> <directory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\src\test\resources</directory> </testResource> </testResources> <directory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target</directory> <finalName>project-1.0</finalName> <pluginManagement> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> </plugin> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.3.2</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>default-clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>default-install</id> <phase>install</phase> <goals> <goal>install</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>default-deploy</id> <phase>deploy</phase> <goals> <goal>deploy</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> <executions> <execution> <id>default-site</id> <phase>site</phase> <goals> <goal>site</goal> </goals> <configuration> <outputDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target\site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </execution> <execution> <id>default-deploy</id> <phase>site-deploy</phase> <goals> <goal>deploy</goal> </goals> <configuration> <outputDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target\site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </execution> </executions> <configuration> <outputDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target\site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </plugin> </plugins> </build> <reporting> <outputDirectory>C:\code\gradle-maven-transform\example\smallJavaMultiProject\target\site</outputDirectory> </reporting> </project> 
+5
source share
3 answers

I ended up with another solution. Instead of accepting a single pom.xml root as input, I instead require that the pom.xml set be allowed. I also insert maven-model-builder and call DefaultModelBuilder via DefaultModelBuildingRequest

For instance:

 DefaultModelBuilderFactory factory = new DefaultModelBuilderFactory(); DefaultModelBuilder builder = factory.newInstance(); ModelBuildingRequest req = new DefaultModelBuildingRequest(); req.setProcessPlugins(false); req.setModelResolver(createModelResolver()); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); for (File pomFile : pomFiles) { req.setPomFile(pomFile); Model effectivePom = builder.build(req).getEffectiveModel(); ... } 

Code is here for all interested.

0
source

EffectivePomMojo is the goal of the aggregator. This means that it is called only for the module for which you run it. But you are right that you must also reset all subprojects. The reason this does not happen in your case is related to this line:

 if ( projects.get( 0 ).equals( project ) && projects.size() > 1 ) 

In your case, the last most recent project on the chart (because there are no dependencies on it from any other module). If you add it as a parent for project0 (and only for this module), then it will put your root pom in the 1st position on the graph, and everything will work as you expect.

I can not justify this behavior. Therefore, if you raise a problem in bugtracker, everyone will be helpful :) Please check with us if / when you get an answer.

PS: such issues are easy to solve if you know how to debug Maven plugins. To do this, you can use mvnDebug instead of mvn , and then open the source code of the plugin and connect to a debugging session.

+3
source

You need to specify a parent element in each of your pom.xml submodules in addition to the modules elements in your root project, for example:

 <parent> <groupId>org.gradle.test.performance</groupId> <artifactId>project</artifactId> <version>1.0</version> </parent> 

Otherwise, it will not be selected when the help:effective-pom command is run.

EDIT: some precision as to why the plugin does not work with aggregation. Aggregation (performed with the modules element) is different from Inheritance (using the parent element). However, the plugin documentation clearly states:

The goal of an effective goal is to make visible the POM, which results from the application of interpolation, inheritance, and active profiles.

And there is no mention of aggregated plugins. I believe that this basically means:

I will take the pom that you provide with me, use interpolation, inheritance and active profiles, but NOT aggregation, and give you the result of pom. Deal with it.

+1
source

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


All Articles