10

I have a Maven project with a number of sub modules. Some of these sub modules are packaged as jar that are deployed to a Nexus Maven repository.

The problem I have is that the packaged jar references the parent pom which is not necessarily deployed.

Is there a way for Maven to deploy the effective pom instead of the pom.xml?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Leon
  • 12,013
  • 5
  • 36
  • 59
  • Do you want to replace the content of `pom.xml` by the effective POM during deploy? Why is the parent POM not deployed? Do you realize that the effective POM will also contain whatever settings you have and may publicly expose your passwords? – Tunaki Oct 27 '15 at 10:39
  • That is exact what I want to do. There is no particular reason for the parent pom not being deployed, other than it not adding value. In particular case on this jar will make use of it – Leon Oct 27 '15 at 10:43
  • 1
    Maybe you can use Maven Flatten Plugin with `oss` – Marthym Dec 10 '20 at 17:43

1 Answers1

10

You need to be perfectly aware of the consequences of what you want to do: the effective POM will also contain your current settings (content of settings.xml), thereby possibly publicly exposing whatever passwords you have hard-coded in there. A better solution would be just to deploy the parent POM.

However, if you really want to go down that path, you can have the following configuration:

<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>

This tells the 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 goal.

If you want the pom.properties file also, you will need to create it manually with the maven-antrun-plugin.

Community
  • 1
  • 1
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    In the end I decided to publish the parent pom, still this is pretty useful to know :) – Leon Oct 27 '15 at 11:25