从外部文件读取属性 - Maven

时间:2013-02-05 13:28:29

标签: maven maven-2

我必须阅读多个maven项目共享的属性,为此我尝试使用properties-maven-plugin,如:

<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 deploy时,属性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,但问题仍然存在。

我会感谢任何援助。 谢谢,

1 个答案:

答案 0 :(得分:0)

问题是pom.xml是在比插件加载更早的时候读取并与属性进行交互的。您可以将插件用于构建中的值 - 例如插件之间的插件,但是您尝试做的事情将不会像那样工作。