我在日常工作中使用maven 2.2.1。最近我发现我的“maven install”变得非常慢(大约慢了3倍)。
在进行了很多编译和调试之后,我发现它的许多RELEASE和LATEST版本依赖(曾经是特定的数字)妨碍了编译进度。我知道“RELEASE”和“LATEST”都是maven中不推荐使用的函数,不应该再使用了。但是,采用“RELEASE”和“LATEST”是我在工作中无法改变的事情。我只能试试运气。他们在这里:
public class DefaultMavenProjectBuilder extends AbstractLogEnabled
implements MavenProjectBuilder, Initializable, Contextualizable
{
private Map processedProjectCache = new HashMap();
public MavenProject buildFromRepository( Artifact artifact,...) {
String cacheKey = createCacheKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); // <========= the "get key"
MavenProject project = (MavenProject) processedProjectCache.get( cacheKey );
if ( project != null )
{
return project;
}
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel );
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
MavenProject mavenProject = buildInternal("Artifact [" + artifact + "]", model, config, remoteArtifactRepositories,
null, false);
return mavenProject;
}
private MavenProject buildInternal(String pomLocation,
Model model,
ProjectBuilderConfiguration config,
List parentSearchRepositories,
File projectDescriptor,
boolean strict, String cacheKey)
throws ProjectBuildingException
{
//...
cacheKey = createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ); // <========= the "set key"
processedProjectCache.put( cacheKey, project );
//...
}
}
我发现主要原因是buildInternal()被调用了10次以上。导致这种情况的原因是,“设置密钥”和“获取密钥”变得不同,例如: 设置键:com.foo:bar:DELELASE 获取密钥:com.foo:bar:1.0.11
我的计划是将“获取密钥”传递给buildInternal,并直接用作“设置密钥”,但不确定这不会破坏其他东西......
有什么建议吗?
提前感谢:)