Maven打包有效pom

Maven package effective pom

我有一个包含许多子模块的 Maven 项目。其中一些子模块被打包为部署到 Nexus Maven 存储库的 jar。

我遇到的问题是打包后的jar引用了不一定部署的父pom。

有没有办法让 Maven 部署有效的 pom 而不是 pom.xml

你需要完全清楚你想做的事情的后果:the effective POM 还将包含你当前的设置(settings.xml 的内容),因此可能公开你拥有的任何密码硬编码在那里。 更好的解决方案是部署父 POM

但是,如果你真的想走那条路,你可以有以下配置:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
        </archive>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-help-plugin</artifactId>
    <version>2.1.1</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>effective-pom</goal>
            </goals>
            <configuration>
                <output>${project.build.outputDirectory}/META-INF/maven/${project.groupId}/${project.artifactId}/pom.xml</output>
            </configuration>
        </execution>
    </executions>
</plugin>

这说明了 maven-jar-plugin not to add the Maven descriptor pom.xml and pom.properties to the jar. Instead, the pom.xml is generated by the maven-help-plugin and its effective-pom 目标。

如果您还需要 pom.properties 文件,则需要使用 maven-antrun-plugin.

手动创建它