【发布时间】:2013-02-05 22:58:57
【问题描述】:
我必须读取由多个 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,但问题仍然存在。
我会感谢任何帮助。 谢谢,
【问题讨论】:
-
您的 conf.properties 似乎被忽略了。你怎么指?如果你运行
mvn deploy -Dnexusurl=http://localhost:8081/nexus/content/repositories/snapshots会发生什么? -
不,属性文件没有被忽略,问题是 carlspring 的回答所描述的,
部分中的值是在最初加载 POM 时分配的。 properties-maven-plugin 仅影响加载属性点之后的插件执行。