maven属性插件:运行“mvn deploy”时的奇怪行为

时间:2012-03-21 12:44:09

标签: maven

我有一个与maven属性插件相关的问题。 我的问题有点与之相关 How to read an external properties file in Maven

根据该文章的建议,我已设法让它完成我想要它做的大部分工作。 我的配置如下所示:

<dependency>
    <groupId>org.kuali.maven.plugins</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.8</version>
</dependency>
...


<plugin>
    <groupId>org.kuali.maven.plugins</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.8</version>

    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${basedir}/${environment}.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

现在,我遇到的问题如下: 我已经配置了一个简单的存储库来存储内容,如下所示:

<distributionManagement>
    <repository>
        <id>localRep</id>
        <url>file:${localRepositoryLocation}</url>
    </repository>
</distributionManagement>

运行mvn deploy时,$ {localRepositoryLocation}不会被替换。

[INFO] --- maven-deploy-plugin:2.5:deploy (default-deploy) @ SomeApp ---
Uploading: file:${localRepositoryLocation}/SomeApp/SomeApp/1.0.0/SomeApp-1.0.0.war
Uploaded: file:${localRepositoryLocation}/SomeApp/SomeApp/1.0.0/SomeApp-1.0.0.war (5754 KB at 18322.3 KB/sec)
Uploading: file:${localRepositoryLocation}/SomeApp/SomeApp/1.0.0/SomeApp-1.0.0.pom
Uploaded: file:${localRepositoryLocation}/SomeApp/SomeApp/1.0.0/SomeApp-1.0.0.pom (7 KB at 2051.1 KB/sec)

另外,我应该注意到我也在mojo版本中使用了该插件,它产生了完全相同的行为。 因此,如果来自两个不同提供商的相同插件具有相同的结果,那么我必须在这里做错了。

有人能帮忙吗?

亲切的问候, 安德烈

1 个答案:

答案 0 :(得分:5)

首先,两个插件都不同。原始codehaus plugin<version>1.0-alpha-2</version>中可用,目标properties:read-project-properties的配置需要files属性:

<configuration>
    <files>
        <file>etc/config/dev.properties</file>
    </files>
</configuration>

<version>1.1.10</version> <configuration> <locations> <location>classpath:META-INF/spring/database.properties</location> </locations> </configuration> classpath:myprops.properties中可用,与原始插件相比是扩展版本,配置需要位置属性:

<plugin>
    <groupId>org.kuali.maven.plugins</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.1.10</version>
    <configuration>
        <locations>
            <location>classpath:META-INF/spring/database.properties</location>
        </locations>
    </configuration>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
        </execution>
    </executions>
</plugin>

在这里你可以看到改进,插件代码的引用:

可以找到属性文件的位置。 Spring资源加载可以理解的任何url都是有效的。例如{{1}}。支持.properties和.xml样式属性。

代码中的问题是示例(来自codehaus文档)是错误的。正确的配置如下:

{{1}}

如您所见,配置标记不在执行标记下。

相关问题