[英]Upgrading maven from 3.0.5 from 3.1.0
我目前在Java Web項目中使用maven 3.0.5。 該工件使用RepositarySystem類讀取Maven工件。 該項目運行正常,沒有任何問題。 但是,當我嘗試升級Maven版本時,theetherether.RepositorySystem會引發錯誤。
我已經參考了一些在線文檔,並且了解到Maven開始從org.eclipse.aether.RepositorySystem提供RepositorySystem,而已經從org.sonatype.aether.RepositorySystem提供了Jar。
但是問題是現在我希望我的項目在版本3.0.5以及最新版本上運行都沒有錯誤。 是否有可能根據Maven版本加載類文件。
請指導我擺脫這個錯誤? 提前致謝。
我的堆棧跟蹤如下:
[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
創建一個在您現在使用ether.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();
}
}
}
這兩個實現必須在使用單獨版本的Maven的單獨jar中進行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.