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

And*_*rei 1 maven

我有一个与maven属性插件相关的问题.我的问题与如何在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>
Run Code Online (Sandbox Code Playgroud)

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

<distributionManagement>
    <repository>
        <id>localRep</id>
        <url>file:${localRepositoryLocation}</url>
    </repository>
</distributionManagement>
Run Code Online (Sandbox Code Playgroud)

运行时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)
Run Code Online (Sandbox Code Playgroud)

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

有人能帮忙吗?

亲切的问候,安德烈

Chr*_*ipp 5

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

<configuration>
    <files>
        <file>etc/config/dev.properties</file>
    </files>
</configuration>
Run Code Online (Sandbox Code Playgroud)

所述kuali-插件是可用的<version>1.1.10</version>并且是相对于原来的插件的扩展版本,配置需要的位置属性:

<configuration>
    <locations>
        <location>classpath:META-INF/spring/database.properties</location>
    </locations>
</configuration>
Run Code Online (Sandbox Code Playgroud)

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

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

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

<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>
Run Code Online (Sandbox Code Playgroud)

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