Maven 以太,从当地的回购处得到神器

Maven 以太,从当地的回购处得到神器,maven,aether,jcabi,Maven,Aether,Jcabi,有许多问题与此有关 <dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-aether</artifactId> <version>0.9</version> </dependency> 神器在本地回购中,但以太找不到它。。。 我做错了什么 我的代码: 列表remoteRepos,文件localrepoot是从

有许多问题与此有关

<dependency>
    <groupId>com.jcabi</groupId>
    <artifactId>jcabi-aether</artifactId>
    <version>0.9</version>
</dependency>
神器在本地回购中,但以太找不到它。。。 我做错了什么

我的代码: 列表remoteRepos,文件localrepoot是从maven插件“注入”的。这个类是从maven插件中使用的

MavenHelperAether(List<RemoteRepository> remoteRepos, File localRepoRoot) {
        this.remoteRepos = remoteRepos
        this.localRepoRoot = localRepoRoot
    }

    /**
     * Resolves artifact using artifact coordinates
     * @param artifactCoords is an artifact you need
     * @param remoteLookup is ignored. It's a part of backward compatibility.
     *
     * @return {@link File} pointing to artifact
     * */
    public File resolveArtifact(String artifactCoords, boolean remoteLookup = false){
        LOG.debug("resolving artifact $artifactCoords ... using localRepo[$localRepoRoot.absolutePath] and remoteRepos [$remoteRepos]")

        def aether = new Aether(remoteRepos, localRepoRoot)
        def artifact = new DefaultArtifact(artifactCoords)
        Collection<Artifact> deps = []
        try{
            deps = resolveInRemoteRepositories(aether, artifact)
            LOG.debug("Resolved artifact path ${deps.iterator().next().file.absolutePath }")
            return deps.iterator().next().file
        }
        catch (DependencyResolutionException | IllegalArgumentException e){
            LOG.warn("Can't fetch $artifact from remote repos. Falling back to local repository...", e)
            def localArtifact = resolveInLocalRepo(artifact)
            if(localArtifact.exists()){
                return  localArtifact;
            }else{
                throw new InstallerException("Can't locate artifact [$artifact] in local repo using path [$localArtifact.absolutePath]")
            }
        }
    }

    private Collection<Artifact> resolveInRemoteRepositories(Aether aether, DefaultArtifact artifact){
        LOG.debug("Trying to resolve $artifact in remote repositories...")
        aether.resolve(artifact,JavaScopes.RUNTIME)
    }

    private  File resolveInLocalRepo(DefaultArtifact artifact){
        LOG.debug("Trying to resolve $artifact in local repository...")
        def localRepoManager = new SimpleLocalRepositoryManager(localRepoRoot)
        new File(localRepoManager.getPathForArtifact(artifact, true))
    }
MavenHelperAether(列出remoteRepos,文件localrepoot){
this.remoteRepos=remoteRepos
this.localrepoot=localrepoot
}
/**
*使用工件坐标解析工件
*@param artifactCoords是您需要的神器
*@param remoteLookup被忽略。这是向后兼容性的一部分。
*
*@return{@link File}指向工件
* */
公共文件resolveArtifact(字符串artifactCoords,布尔remoteLookup=false){
LOG.debug(“使用localRepo[$LocalRepoot.absolutePath]和remoteRepos[$remoteRepos]解析工件$artifactCoords…”
def乙醚=新乙醚(remoteRepos、LocalRepoot)
def artifact=新的DefaultArtifact(artifactCoords)
收款部门=[]
试一试{
deps=resolveInRemoteRepositories(以太、人工制品)
LOG.debug(“已解析的工件路径${deps.iterator().next().file.absolutePath}”)
返回deps.iterator().next().file
}
捕获(依赖解析异常|非法辩论异常e){
LOG.warn(“无法从远程repos获取$artifact。正在回退到本地存储库…”,e)
def localArtifact=resolveInLocalRepo(工件)
if(localArtifact.exists()){
返回本地工件;
}否则{
抛出新的InstallerException(“无法使用路径[$localArtifact.absolutePath]在本地repo中定位工件[$artifact])
}
}
}
私有集合解析存储库(以太、默认工件){
debug(“尝试在远程存储库中解析$artifact…”)
resolve(工件,JavaScopes.RUNTIME)
}
私有文件resolveInLocalRepo(DefaultArtifact工件){
调试(“尝试在本地存储库中解析$artifact…”)
def localrepositorymanager=新的SimpleLocalRepositoryManager(localrepoot)
新文件(localRepoManager.getPathForArtifact(工件,true))
}

我不能说它是好是坏,但我用过这段代码,它是有效的:

 private  File resolveInLocalRepo(DefaultArtifact artifact){
        LOG.debug("Trying to resolve $artifact in local repository...")
        def localRepoManager = new SimpleLocalRepositoryManager(localRepoRoot)
        def pathToLocalArtifact = localRepoManager.getPathForLocalArtifact(artifact)
        LOG.debug("pathToLocalArtifact: [$pathToLocalArtifact]")
        new File("$localRepoRoot.absolutePath/$pathToLocalArtifact")
    }

localrepoot是一个指向本地repo根的文件。

您只需创建本地远程repo并将其交给请求:

RemoteRepository local = new RemoteRepository.Builder("local", "default", "file:c:/Users/blah/.m2/repository").build(); RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2/").build(); collectRequest.setRepositories( Arrays.asList(local, central)); RemoteRepository local=new RemoteRepository.Builder(“local”、“default”、“file:c:/Users/blah/.m2/repository”).build(); RemoteRepository central=新的RemoteRepository.Builder(“central”、“default”和http://central.maven.org/maven2/build(); collectRequest.setRepositories(Arrays.asList(local,central));
看看这段代码:

以太默认使用本地存储库,因此如果不需要,只需设置为不使用远程:

    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession()
    session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER)

你的代码看起来怎么样?如果没有您的代码,就不可能看到发生了什么。小心,我是为maven 3.0.x做的,maven 3.1.x有不兼容的api更改。您必须更改AETHERE的软件包名称谢谢!是否有可能转换回购优先权?我没有调查,但我认为答案就在源头附近。远程回购的结构与本地回购不同。此外,maven尝试从您的伪远程复制到本地,但失败了。
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession()
    session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER)