2013-02-05 29 views
0

我不得不讀財產多Maven項目共享,爲此,我嘗試使用屬性 - Maven的插件,如:讀取屬性 - Maven的

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>properties-maven-plugin</artifactId> 
      <version>1.0-alpha-1</version> 
       <configuration> 
       <files> 
        <file>conf.properties</file> 
       </files> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>initialize</phase> 
        <goals> 
         <goal>read-project-properties</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     </plugins> 
     </build> 

<distributionManagement> 
    <snapshotRepository> 
     <id>snapshots</id> 
     <url>${nexusurl}</url> 
    </snapshotRepository> 
</distributionManagement> 
</project>  

和文件conf.properties包含:

nexusurl=http://localhost:8081/nexus/content/repositories/snapshots 

的問題是,使用MVN部署時,該屬性nexusurl沒有解決,錯誤跟蹤結果是:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
(default- deploy) on project parent: Failed to deploy artifacts/metadata: No connector 
available to access repository snapshots (${nexusurl}) of type default using the 
available factories WagonRepositoryConnectorFactory -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute 
goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on 
project parent: Failed to deploy artifacts/metadata: No connector available to 
access repository snapshots (${nexusurl}) of type default using the available 
factories WagonRepositoryConnectorFactory 

我試圖改變插件的執行階段(驗證,安裝,部署),將插件的版本更改爲1.0-alpha-2,但問題依然存在。

我會感謝任何援助。 謝謝,

+0

你的conf.properties似乎被忽略。你如何參考?如果你運行'mvn deploy -Dnexusurl = http:// localhost:8081/nexus/content/repositories/snapshots'會發生什麼? – MrsTang

+1

不,屬性文件不會被忽略,問題是用carlspring的回答描述的問題,部分中的值在最初加載POM時分配。 properties-maven-plugin隻影響加載屬性之後的插件執行。 –

回答

0

問題是,pom.xml被讀取並與你的插件加載早得多的屬性inteporlated。你可以在你的構建中爲插件使用插件 - 例如插件之間的插件,但是你想做的事情不會像那樣工作。

+0

您是否可以通過其他方式或插件傳遞屬性? –

+0

插件將不適用於您的情況。 Maven將屬性內插到加載的POM模型中的方式非常重要。爲了達到這個目的,你必須通過命令行傳遞變量(我幾乎看不出這樣做的好處)。爲了便於攜帶,您需要保留''URL的硬編碼。 – carlspring

+0

把某些東西當作屬性是有意義的,但是這個並不完全屬於它們。 – carlspring