When a maven build has a parent that is not the latest release version, the goal of the versions plugin display-parent-updates is reporting it nicely but I would like to report this somehow:
Any suggestions?
I achieved this in 2 steps :
1. Use of the following plugin
`<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<executions>
<execution>
<id>display-dkv-boot-starter-parent-updates</id>
<phase>initialize</phase>
<goals>
<goal>display-parent-updates</goal>
</goals>
<configuration>
<allowSnapshots>true</allowSnapshots>
</configuration>
</execution>
</executions>
</plugin>`
Use of the enforce plugin with a custom rule
public class MyCustomRule implements EnforcerRule2 {
private boolean fail = false;
@Override
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
Log log = helper.getLog();
List<String> lines = Collections.emptyList();
try {
Path path = Paths.get((String) helper.evaluate("${versions.outputFile}"));
lines = Files.readAllLines(path);
fail = lines.stream()
.anyMatch(l -> l.contains("The parent project has a newer version"));
} catch (Exception ex) {
log.warn(ex);
fail = false;
}
if (this.fail) {
throw new EnforcerRuleException(lines.toString());
}
}
@Override
public boolean isCacheable() {
return false;
}
@Override
public boolean isResultValid(EnforcerRule enforcerRule) {
return fail;
}
@Override
public String getCacheId() {
return null;
}
@Override
public EnforcerLevel getLevel() {
return EnforcerLevel.WARN;
}
}