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 ;
78import org .gradle .api .plugins .quality .CheckstyleExtension ;
89import org .gradle .api .plugins .quality .CheckstylePlugin ;
910import org .gradle .api .tasks .TaskAction ;
10- import org .gradle .util .VersionNumber ;
1111
1212import java .io .BufferedWriter ;
1313import java .io .File ;
@@ -22,7 +22,7 @@ public class CheckstyleSetup extends DefaultTask {
2222
2323 // Recent checkstyle versions flag an annotation array indentation which is widely used at HMCTS.
2424 // Consequently we don't force recent versions onto teams (but they may opt in).
25- public static final String minCheckstyleVersion = "8.31" ;
25+ public static final ComparableVersion minCheckstyleVersion = new ComparableVersion ( "8.31" ) ;
2626
2727 public static void apply (Project project ) {
2828 project .getPlugins ().apply (CheckstylePlugin .class );
@@ -39,9 +39,9 @@ public static void apply(Project project) {
3939 if (checkstyleTask .getConfigFile () == null || !checkstyleTask .getConfigFile ().exists ()) {
4040 // If using bundled checkstyle config, set a floor for checkstyle version since older versions may
4141 // not support our bundled config.
42- if ( VersionNumber . parse ( minCheckstyleVersion )
43- .compareTo (VersionNumber . parse ( ext . getToolVersion ()) ) > 0 ) {
44- ext .setToolVersion (minCheckstyleVersion );
42+ ComparableVersion currentCheckStyleVersion = new ComparableVersion ( ext . getToolVersion ());
43+ if ( minCheckstyleVersion .compareTo (currentCheckStyleVersion ) > 0 ) {
44+ ext .setToolVersion (ext . getToolVersion () );
4545 }
4646
4747 checkstyleTask .setConfigFile (writer .configFile );
0 commit comments