mojohaus / flatten-maven-plugin

Flatten Maven Plugin
https://www.mojohaus.org/flatten-maven-plugin/
Apache License 2.0
205 stars 84 forks source link

Keep comments on flattened pom #269

Closed ca-stefan-cordes closed 2 years ago

ca-stefan-cordes commented 2 years ago

We are using resolveCiFriendliesOnly for all our projects with

...
        <version.flatten-maven-plugin>1.2.7</version.flatten-maven-plugin>
...
            <plugin>
                <!-- for https://maven.apache.org/maven-ci-friendly.html -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>${version.flatten-maven-plugin}</version>
                <configuration>
                    <!-- The flag to indicate if the generated flattened POM shall be set as POM file  -->
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>resolveCiFriendliesOnly</flattenMode>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten-resolveCiFriendliesOnly</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>

and the generated .flattened-pom.xml no longer contains any comment.

As the original pom.xml is available in the SourceCodeManagement only (or on some developer locals) most developers are accessing the "pom.xml" by looking in our nexus-repository via maven-pom-editors function.

We have some nice comments in front of some properties, for example

        <!-- https://github.com/spring-projects/spring-framework/releases -->
        <springVersion>5.3.18</springVersion>

but in the nexus (flattened-pom) they are no longer visible.

Would be nice to keep comments during flatten process.

ca-stefan-cordes commented 2 years ago

As the MavenXpp3Writer is used to write the modified content this probably should be handled in core by changing the MavenXpp3Reader to grab all org.w3c.dom.CharacterData / org.w3c.dom.Comment / org.w3c.dom.Text store it in the org.apache.maven.model.Model and write it in the MavenXpp3Writer.

Similar was requested for Properties order: https://issues.apache.org/jira/browse/MNG-6801 Another similar for GenerateReleasePomsPhase is: https://issues.apache.org/jira/browse/MRELEASE-995 And here two very old which were not fixed: https://issues.apache.org/jira/browse/MNG-4 (comment+formatting) and https://issues.apache.org/jira/browse/MNG-1117 (formatting)