Ekryd / sortpom

Maven plugin that helps the user sort pom.xml.
https://github.com/Ekryd/sortpom/wiki/
BSD 3-Clause "New" or "Revised" License
334 stars 178 forks source link

sorting doesn't work in >=v3.0.0 #272

Closed YNedderhoff closed 1 year ago

YNedderhoff commented 1 year ago

Hey,

I have this config:

<plugin>
  <groupId>com.github.ekryd.sortpom</groupId>
  <artifactId>sortpom-maven-plugin</artifactId>
  <configuration>
    <predefinedSortOrder>recommended_2008_06</predefinedSortOrder>
    <verifyFail>stop</verifyFail>
    <verifyFailOn>strict</verifyFailOn>
  </configuration>
  <executions>
    <execution>
      <id>verify</id>
      <goals>
        <goal>verify</goal>
      </goals>
      <phase>validate</phase>
    </execution>
  </executions>
</plugin>

In a very much not sorted pom, when using 3.2.0 and running mvn sortpom:sort, it just says Pom file is already sorted, exiting. Was there a breaking change that breaks my config?

YNedderhoff commented 1 year ago

Ok, after further investigation, it turns out that it does sort, it just happens to sort only the top level pom tags (dependencyManagement, dependencies, plugins, ...). But on the lower level, i.e. dependency, it doesn't. I think recommended_2008_06 used to though, no?

Ekryd commented 1 year ago

Hi! Beginning with 3.0.0, I made a few common parameters default (such as keeping empty lines). The older plugin contained a switch between the order of artefact and group name and that is perhaps why the file resorted in later versions. Do you still have a problem?

YNedderhoff commented 1 year ago

Is there a detailed changelog somewhere where I can see what has been changed?

My problem is a slightly different one though, I think at least? My problem is that dependencies within <dependencies> and <dependencyManagement> are not being sorted alphabetically anymore with the above config. With an older version, they were. The same for plugins.

Ekryd commented 1 year ago

That sounds weird. I don't have a more detailed changelog than the news: https://github.com/Ekryd/sortpom#news, unless you want to parse the code itself.

Can you post a complete example pom to show the problems in detail. That way I can run the same sorting to see what happens.

Ekryd commented 1 year ago

I may have an idea what is happening. The <predefinedSortOrder>recommended_2008_06</predefinedSortOrder> just says in which order elements should be placed, like dependencies before plugins. In order to sort the order within the dependencies, you must specify that order with a parameter like <sortDependencies>scope,groupId,artifactId</sortDependencies> (and same for sortPlugins).

YNedderhoff commented 1 year ago

Hey, sorry I didn't get around to do that example, yet.

On your latter comment: That's interesting. Was this different before? Because I definitely remember my dependencies being sorted correctly before.

Ekryd commented 1 year ago

I think that the change to customized sorting for dependencies and plugin was was done in 2.1.0. 2012-09-23 | 2.1.0 | The parameters sortDependencies and sortPlugins are remade for greater flexibility.

If no sorting of dependencies is specified, the existing order of the dependencies is just kept. You would never get a randomized order.

atkawa7 commented 1 year ago

@Ekryd @YNedderhoff I have the same issue. Its not sorting as well after upgrade

atkawa7 commented 1 year ago

@Ekryd @YNedderhoff When I sort via terminal

 mvn com.github.ekryd.sortpom:sortpom-maven-plugin:3.2.0:sort -Dsort.sortDependencies=scope,groupId,artifactId  -DsortProperties=true

but this doesn't sort

 mvn com.github.ekryd.sortpom:sortpom-maven-plugin:3.2.0:sort -Dsort.sortDependencies=groupId,artifactId  -DsortProperties=true

I don't understand is scope required

Ekryd commented 1 year ago

@atkawa7 scope means that SortPom sorts by scope first (i.e compile dependencies first and test dependencies last). Can you give me an example of the pom-file that you are sorting?

YNedderhoff commented 1 year ago

the existing order of the dependencies is just kept. You would never get a randomized order.

I think that's what I meant, yeah. But I feel like this behaviour wasn't the case before, was it?