2014-06-13 3 views
0

현재 내 Java 웹 프로젝트에서 maven 3.0.5를 사용 중입니다. 이 아티팩트는 RepositarySystem 클래스를 사용하여 메이븐 아티팩트를 읽습니다. 이 프로젝트는 문제없이 잘 실행됩니다. 하지만 maven 버전을 업그레이드하려고 할 때 aether.RepositorySystem은 오류를 발생시킵니다.3.1.5에서 3.0.5로 업그레이드하기

일부 온라인 문서를 참조하고 Maven이 org.eclipse.aether에서 RepositorySystem을 제공하기 시작했다는 사실을 알게되었습니다 .RepositorySystem은 org.sonatype.aether.RepositorySystem의 Jar를 제공했습니다.

하지만 지금 문제는 내 프로젝트가 최신 버전뿐만 아니라 버전 3.0.5에서도 오류없이 실행되기를 바랍니다. 메이븐 버전에 따라 클래스 파일을로드 할 수있는 가능성이 있습니까?

이 오류를 없애시겠습니까? 미리 감사드립니다. 내 스택 추적은 다음

,

[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 
+0

관련이없는 버그 픽스가있는 3.1.1을 사용하지 않는 이유는 무엇입니까? – Gimby

+0

Nim Gimby. 이 maven 다음에 org.eclipse로부터 aethor api를 제공하기 때문에 나는 3.0.5 이후의 어떤 maven 버전에서도 이것을 실행할 수 없었다. –

+0

Maven 플러그인을 개발하고 있습니까? 아니면 무엇을하고 있습니까? 일부 코드 조각을 보여줄 수 있습니까? – khmarbaise

답변

0

은 당신이 지금 aether.RepositorySystem 또는 관련 클래스를 사용하여 위치를 어디서나 사용할 수있는 인터페이스를 만듭니다.

하나는 이전 버전을, 하나는 새 버전을 기반으로 두 가지 구현을 작성하십시오.

마지막으로 새로운 버전을 기반으로 구현을 인스턴스화하려고하는 작은 Factory를 만듭니다. 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(); 
     } 
    } 
} 

처럼 보일 것입니다.

+0

감사합니다 Jens .. 희망 당신은 나를 얻고 있습니다. 이 문제에 대한 코드 스 니펫을 제공하십시오. 왜냐하면 나는 메이븐 버전에 익숙하지 않기 때문이다. 일부 코드를 사용하면 더 많은 도움이됩니다. –

+0

내 편집을 참조하십시오. HTH –

+0

훌륭한 작품입니다. 감사. –

관련 문제