1

我在日常工作中使用 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 倍以上。造成这种情况的原因是“set key”和“get key”变得不同,例如: set key: com.foo:bar:RELEASE get key: com.foo:bar:1.0.11

我的计划是将“get key”传递给buildInternal,并直接用作“set key”,但不确定这不会破坏其他东西......

有什么建议吗?

提前致谢 :)

4

0 回答 0