Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep parent node #78

Closed
bertramn opened this issue Sep 26, 2018 · 7 comments
Closed

Keep parent node #78

bertramn opened this issue Sep 26, 2018 · 7 comments

Comments

@bertramn
Copy link

When building a multi module project, parent elements are removed from the flattened pom. We want to build a parent pom for downstream consumption that inherits from an upstream pom which includes some profiles used for CI tasks. Unfortunately with $(revision} in the way and ${project.version} expanding too early and not to the right value if used in downstream poms, we have to resort to a flatten process. Unfortunately flatten strips all parent pom elements. Also tried PR #77 to keep the parent but the code falls over when we import something with properties in the dependency management section. Would it be possible to add a configuration item to keep a property expanded parent element in the pom?

@danhaywood
Copy link

danhaywood commented Sep 26, 2018 via email

@bertramn
Copy link
Author

bertramn commented Sep 26, 2018

Yes that works great - thanks heaps. I thought I was going mental but just checked again ... not a single ittest has this syntax as example and I cannot find anything in the docs either.

$ find . -name 'pom.xml' -type f -exec grep '<parent>resolve' {} +
$

Even seems to works with the ${revision} in maven 3.5.4 ... need to do some more testing but looks promising.

@danhaywood
Copy link

danhaywood commented Sep 26, 2018 via email

@bertramn
Copy link
Author

Hmm would that not just be a variation of a flatten mode? Looks like some ticker time is required :)

@McFoggy
Copy link

McFoggy commented Nov 23, 2018

@bertramn I think #80 answers your need. You could then specify the behavior you would expect for each POM node.

@hohwille
Copy link
Member

Maybe our documentation is not so great but what you want can be done with flatten plugin from the beginning:
http://www.mojohaus.org/flatten-maven-plugin/flatten-mojo.html#pomElements
If I miss something feel free to reopen.

@xak2000
Copy link

xak2000 commented Sep 16, 2021

Maybe our documentation is not so great but what you want can be done with flatten plugin from the beginning:
http://www.mojohaus.org/flatten-maven-plugin/flatten-mojo.html#pomElements

@hohwille Unfortunately the documentation is pretty unclear at this topic.

It documents the existence of pomElements, but it's unclear what to put inside of this element.

Fortunately it's Java type is documented: org.codehaus.mojo.flatten.FlattenDescriptor. Here we see some set of setters. I suppose each setter becomes an child XML tag of <pomElements> tag. Here we also see that setters argument is ElementHandling enum in most cases and it's possible values are:

  • expand - Take the element from the effective POM.
  • flatten - Flatten the element. For most elements this means that they will be removed and are not present in the flattened POM.
  • interpolate - Take the element from the interpolated POM (original POM with variables interpolated).
  • keep - Take the element untouched from the original POM.
  • remove - Remove the element entirely so it will not be present in flattened POM.
  • resolve - Take the element from the resolved POM.

The example of POM with <pomElements> tag:

	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>flatten-maven-plugin</artifactId>
				<version>1.2.2</version>
				<configuration>
					<updatePomFile>true</updatePomFile>
					<flattenMode>resolveCiFriendliesOnly</flattenMode>
					<pomElements>
						<parent>flatten</parent>
						<dependencies>flatten</dependencies>
					</pomElements>
				</configuration>
				<executions>
					<execution>
						<id>flatten</id>
						<phase>process-resources</phase>
						<goals>
							<goal>flatten</goal>
						</goals>
					</execution>
					<execution>
						<id>flatten-clean</id>
						<phase>clean</phase>
						<goals>
							<goal>clean</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

So, currently the only way to know all possible inner tags and their values is to guess them based on Javadocs.

If I understand it right, the generic approach to know what to put inside <pomElements> tag is:

  1. Open Javadocs and find the appropriate setter. It would be a tag name (without set prefix). Alternatively the same tags are list in the fist table on this page (but it's unclear from the docs that this table actually represents possible children of <pomElements> element).
  2. Check the setter's value type. Usually it will be ElementHandling.
  3. Use appropriate tag name with appropriate value.

I hope this will help someone who will find this issue as I did when I wondered what I actually can put inside <pomElements> tag as it's not documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants