6262import org .apache .maven .model .Plugin ;
6363import org .apache .maven .model .PluginExecution ;
6464import org .apache .maven .plugin .MojoExecution ;
65+ import org .apache .maven .rtinfo .RuntimeInformation ;
6566import org .slf4j .Logger ;
6667import org .slf4j .LoggerFactory ;
6768
@@ -102,17 +103,19 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon
102103
103104 private final XmlService xmlService ;
104105 private final MavenSession session ;
106+ private final RuntimeInformation rtInfo ;
105107
106108 private volatile CacheState state ;
107109 private CacheConfig cacheConfig ;
108110 private HashFactory hashFactory ;
109111 private List <Pattern > excludePatterns ;
110112
111113 @ Inject
112- public CacheConfigImpl ( XmlService xmlService , MavenSession session )
114+ public CacheConfigImpl ( XmlService xmlService , MavenSession session , RuntimeInformation rtInfo )
113115 {
114116 this .xmlService = xmlService ;
115117 this .session = session ;
118+ this .rtInfo = rtInfo ;
116119 }
117120
118121 @ Nonnull
@@ -126,7 +129,14 @@ public CacheState initialize()
126129 if ( state == null )
127130 {
128131 final String enabled = getProperty ( CACHE_ENABLED_PROPERTY_NAME , "true" );
129- if ( !Boolean .parseBoolean ( enabled ) )
132+
133+ if ( !rtInfo .isMavenVersion ( "[3.9.0-SNAPSHOT,)" ) )
134+ {
135+ LOGGER .warn ( "Cache requires Maven >= 3.9, but version is " + rtInfo .getMavenVersion ()
136+ + ". Disabling cache." );
137+ state = CacheState .DISABLED ;
138+ }
139+ else if ( !Boolean .parseBoolean ( enabled ) )
130140 {
131141 LOGGER .info (
132142 "Cache disabled by command line flag, project will be built fully and not cached" );
0 commit comments