2014-01-23 26 views
0

我創建的庫最終將成爲其他項目可以使用的maven工件。它使用RESTlet作爲REST客戶端。創建依賴於RESTlet的maven工件 - 如何處理版本

儘管我的工件/庫是平臺中立的,但它的依賴關係卻不是。 RESTlet有多個版本,GAE有一個,JEE有一個等等。每個版本都有自己的組ID,org.restlet。 GAE例如:

<dependency> 
    <groupId>org.restlet.gae</groupId> 
    <artifactId>org.restlet</artifactId> 
    <version>2.2-M6</version> 
</dependency> 

理想我想圖書館的用戶能夠指定準確的Restlet版自己。打包我的磁帶庫的最佳方式是什麼,這將最大限度地減少用戶的ha?聲?

我已經看了一遍,但找不到這種事情的指導/最佳實踐。

+1

我不知道如果我理解你的問題(因此現在添加一個評論而不是答案),但會[可選的依賴關係](http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies .html#Optional_Dependencies)在這裏幫助你?您可以在項目中用'可選'標記所有的依存關係。然後,您的庫的用戶可以自由定義他們自己想要使用的restlet版本的依賴關係。 – DB5

+0

這可能是解決問題的好方法。我會看看。謝謝。 – tom

回答

1

我有同樣的確切情況。我有一個依賴Restlet的Java庫,由我的GAE服務器和我的Android客戶端使用。

對於lib,我將restlet依賴項標記爲可選項,並指定「provided」作用域,因爲它由包含應用程序提供。我在構建lib時使用了jse版本,但我認爲不管你使用哪一個版本;因爲界面是一樣的。

<dependency> 
    <groupId>org.restlet.jse</groupId> 
    <artifactId>org.restlet</artifactId> 
    <version>${restlet.version}</version> 
    <optional>true</optional> 
    <scope>provided</scope> 
</dependency> 

對於我的Android客戶端,我指定了android版:

<dependency> 
    <groupId>org.restlet.android</groupId> 
    <artifactId>org.restlet</artifactId> 
    <version>${restlet.version}</version> 
</dependency> 

而對於我的GAE服務,我指定的GAE版本:

<dependency> 
    <groupId>org.restlet.gae</groupId> 
    <artifactId>org.restlet</artifactId> 
    <version>${restlet.version}</version> 
</dependency> 
+0

這是我現在使用的方法。即使圖書館的用戶必須申報額外的依賴關係,它也比我要發佈多個版本的圖書館要好得多。謝謝。 – tom