【问题标题】:Upgrading maven from 3.0.5 from 3.1.0从 3.1.0 升级 maven 从 3.0.5
【发布时间】:2014-06-16 15:31:44
【问题描述】:

我目前在我的 java web 项目中使用 maven 3.0.5。该工件使用 RepositorySystem 类来读取 Maven 工件。这个项目运行良好,没有任何问题。但是当我尝试升级 maven 版本时, aether.RepositorySystem 会抛出错误。

我参考了一些在线文档并了解到 Maven 开始从 org.eclipse.aether.RepositorySystem 提供 RepositorySystem 而不是已经从 org.sonatype.aether.RepositorySystem 提供了 Jar。

但现在的问题是,我希望我的项目在 3.0.5 版和最新版本上运行时没有错误。有没有可能根据maven版本加载class文件。

请指导我摆脱这个错误?提前致谢。

我的堆栈跟踪如下,

[PhrescoException]:  [ErrorMessage] = [PhrescoException]:  [ErrorMessage] = org.codehaus.plexus.component.repository.exception.ComponentLookupException: com.google.inject.ProvisionException: Guice provision errors:

    No implementation for java.util.Set<org.eclipse.aether.RepositoryListener> was bound.
      while locating java.util.Set<org.eclipse.aether.RepositoryListener>
        for parameter 0 at org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher.<init>(Unknown Source)
      while locating org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher
      at ClassRealm[plexus.core, parent: null]
      at ClassRealm[plexus.core, parent: null]
      while locating org.eclipse.aether.impl.RepositoryEventDispatcher
        for parameter 0 at org.eclipse.aether.internal.impl.DefaultMetadataResolver.<init>(Unknown Source)
      while locating org.eclipse.aether.internal.impl.DefaultMetadataResolver
      at ClassRealm[plexus.core, parent: null]
      at ClassRealm[plexus.core, parent: null]
      while locating org.eclipse.aether.impl.MetadataResolver
        for parameter 0 at org.apache.maven.repository.internal.DefaultVersionResolver.<init>(Unknown Source)
      while locating org.apache.maven.repository.internal.DefaultVersionResolver
      at ClassRealm[plexus.core, parent: null]
      at ClassRealm[plexus.core, parent: null]
      while locating org.eclipse.aether.impl.VersionResolver
        for parameter 0 at org.eclipse.aether.internal.impl.DefaultRepositorySystem.<init>(Unknown Source)
      while locating org.eclipse.aether.internal.impl.DefaultRepositorySystem
      at ClassRealm[plexus.core, parent: null]
      at ClassRealm[plexus.core, parent: null]
      while locating org.eclipse.aether.RepositorySystem

【问题讨论】:

  • 为什么不 3.1.1 有一些相关的错误修正?
  • 不,金比。我无法在 3.0.5 之后的任何 maven 版本上运行它,因为在这个 maven 提供了来自 org.eclipse 的 aethor api 之后。
  • 您是在开发 maven 插件还是在做什么?你能显示一些代码sn-ps吗?

标签: java maven


【解决方案1】:

创建一个您现在使用 aether.RepositorySystem 或相关类的任何地方都可以使用的接口。

写两个实现,一个基于旧版本,一个基于新版本。

最后创建一个尝试基于新版本实例化实现的小工厂。将其包装在 try catch 块中,如果失败,则基于旧版本创建一个。

结果应该有点像这样

public interface RepositorySystem {

    public void doStuff() // add whatever methods you need here

    public DetailWrapper getDetails() // maybe you need more wrapper interfaces and matching implementations, when you aren't dealing with just one class.
}

public class RepositorySystemAdapterPreMavenXXX implements RepositorySystem {
    org.sonatype.aether.RepositorySystem delegate = new org.sonatype.aether.RepositorySystem();
    public void doStuff(){
        delegate.doStuff();
    }

    // ...
}

public class RepositorySystemAdapterPostMavenXXX implements RepositorySystem {
    org.eclipse.aether.RepositorySystem delegate = new org.eclipse.aether.RepositorySystem();
    public void doStuff(){
        delegate.doStuff();
    }

    // ...
}

public class RepositorySystemFactory{
    public static RepositorySystem repositorySystem(){
        try {
            return new RepositorySystemAdapterPostMavenXXX(); // you might have to use reflection to do this ... not completely sure;
        } catch(Error error) { // find out what kind of error/exception you get and catch exactly that
            return  new RepositorySystemAdapterPreMavenXXX();
        }
    }
}

这两个实现必须在单独的 jar 中使用单独的 Maven 版本构建。

【讨论】:

  • 谢谢 Jens.. 希望你能得到我。请为此提供一些代码 sn-ps。因为我是 Maven 版本的新手。当您返回一些代码时,它会有所帮助。
猜你喜欢
  • 1970-01-01
  • 2012-05-11
  • 2022-07-15
  • 2014-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-08
  • 2014-12-18
相关资源
最近更新 更多