[英]Maven `help:effective-pom` only generating for a single project, not all projects
我想為多模塊構建中的所有子項目生成有效的pom。
help:effective-pom
文檔在此處說明
它將遍歷當前構建會話中的所有項目,並為每個項目打印有效的POM。
我在這個Maven項目的根目錄中運行mvn help:effective-pom
,它只是為根而不是子項目生成的。
為什么沒有為所有項目生成有效的pom。 注意:我還有另一個真實世界的maven項目,其中mvn help:effective-pom
正確為每個子模塊生成帶有嵌套<project>
的<projects>
標記。 我不確定為什么這個Maven項目不起作用
這是生成的有效pom
<!-- ====================================================================== -->
<!-- -->
<!-- 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>
EffectivePomMojo是一個聚合器目標。 這意味着僅針對您為其運行的模塊調用它。 但是您說對了,它也應該轉儲所有子項目。 在您的情況下不執行此操作的原因是由於以下原因:
if ( projects.get( 0 ).equals( project ) && projects.size() > 1 )
在您的情況下,最上面的項目在圖形中位於最后(因為其他任何模塊對此都沒有依賴性)。 如果將其作為父項添加到project0(並且僅用於該模塊),則它將根pom置於圖形中的第一位置,一切都會按預期進行。
對於這種行為,我無法提出理由。 因此,如果您在Bugtracker中提出問題,每個人都會受益:)如果/當您得到答案時,請更新我們。
PS:如果您知道如何調試Maven插件,那么這些問題很容易解決。 為此,您可以使用mvnDebug
代替mvn
,然后打開插件的源代碼並附加到調試會話。
除了根項目中的modules
元素外,還需要在每個子模塊pom.xml
中指定parent
元素,例如:
<parent>
<groupId>org.gradle.test.performance</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
</parent>
否則,當您運行help:effective-pom
命令時,它將不會被提取。
編輯:關於為什么插件不能與聚合一起使用的某種精度。 聚合 (使用modules
元素完成)與繼承 (使用parent
元素)不同。 但是,插件文檔中明確提到:
有效pom目標用於顯示由插值,繼承和活動配置文件的應用導致的POM。
並且沒有提到聚合插件。 我相信它基本上意味着:
我將使用您提供的pom,應用插值,繼承和活動配置文件,但不進行聚合,並為您提供生成的pom。 處理它。
最后,我最終提出了另一種解決方案。 我不是接受單個根pom.xml
作為輸入,而是要求解析pom.xml
的集合。 我現在還嵌入maven-model-builder
和調用DefaultModelBuilder
通過DefaultModelBuildingRequest
例如:
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();
...
}
在這里編碼給任何有興趣的人
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.