11package uk .gov .hmcts .tools ;
22
33import lombok .SneakyThrows ;
4+ import org .apache .maven .artifact .versioning .ComparableVersion ;
45import org .gradle .api .DefaultTask ;
56import org .gradle .api .Project ;
67import org .gradle .api .plugins .quality .Checkstyle ;
@@ -22,7 +23,7 @@ public class CheckstyleSetup extends DefaultTask {
2223
2324 // Recent checkstyle versions flag an annotation array indentation which is widely used at HMCTS.
2425 // Consequently we don't force recent versions onto teams (but they may opt in).
25- public static final String minCheckstyleVersion = "8.31" ;
26+ public static final ComparableVersion minCheckstyleVersion = new ComparableVersion ( "8.31" ) ;
2627
2728 public static void apply (Project project ) {
2829 project .getPlugins ().apply (CheckstylePlugin .class );
@@ -39,9 +40,9 @@ public static void apply(Project project) {
3940 if (checkstyleTask .getConfigFile () == null || !checkstyleTask .getConfigFile ().exists ()) {
4041 // If using bundled checkstyle config, set a floor for checkstyle version since older versions may
4142 // not support our bundled config.
42- if ( VersionNumber . parse ( minCheckstyleVersion )
43- .compareTo (VersionNumber . parse ( ext . getToolVersion ()) ) > 0 ) {
44- ext .setToolVersion (minCheckstyleVersion );
43+ ComparableVersion currentCheckStyleVersion = new ComparableVersion ( ext . getToolVersion ());
44+ if ( minCheckstyleVersion .compareTo (currentCheckStyleVersion ) > 0 ) {
45+ ext .setToolVersion (ext . getToolVersion () );
4546 }
4647
4748 checkstyleTask .setConfigFile (writer .configFile );
0 commit comments