jgitver / jgitver/jgitver-maven-plugin

Sort maven properties (proposal with code example)

Open
#185 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
166
Forks
42
PR merge metrics
No merged PRs in 30d

Description

When setting `jgitver.resolve-project-version` to `true` the properties in the pom file are _rewritten_ but these are stored in a `java.util.Properties` which in turn is a `java.util.Hashtable`. So when these properties are _serialized_ to a new pom.xml file, the order of the properties is mixed up.

This can easily be fixed by using a custom `Properties` class which returns the key set as a `TreeSet`:

```
package fr.brouillard.oss.jgitver;

import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;

class SortedProperties extends Properties {
public SortedProperties(Properties properties) {
properties.forEach((key, value) -> setProperty(key.toString(), value.toString()));
}

@Override
public Set keySet() {
return new TreeSet<>(super.keySet());
}
}
```
Use this class as properties for the model that is rewritten as the new pom.xml file. Insert at [JGitverUtils:219](https://github.com/jgitver/jgitver-maven-plugin/blob/1.9.0/src/main/java/fr/brouillard/oss/jgitver/JGitverUtils.java#L219):
```
model.setProperties(new SortedProperties(model.getProperties()));

```

That way, the properties are nicely sorted instead of being mixed up.

I'm not able to build the project myself because I get a `[ERROR] java.lang.ClassNotFoundException: org.apache.maven.surefire.junit4.JUnit4Provider` when building with [./mvnw package](https://github.com/jgitver/jgitver-maven-plugin/blob/master/CONTRIBUTING.md#building-master). I _installed_ it locally by building without tests and verified the result in a project.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.