Skip to content

Commit e82a4a6

Browse files
authored
[MBUILDCACHE-26] Ensure the maven version is >= 3.9.0-SNAPSHOT (apache#32)
1 parent e7b357b commit e82a4a6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.apache.maven.model.Plugin;
6363
import org.apache.maven.model.PluginExecution;
6464
import org.apache.maven.plugin.MojoExecution;
65+
import org.apache.maven.rtinfo.RuntimeInformation;
6566
import org.slf4j.Logger;
6667
import 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

Comments
 (0)