【问题标题】:properties-maven-plugin not working for goal write-project-propertiesproperties-maven-plugin 不适用于目标 write-project-properties
【发布时间】:2018-09-30 13:17:01
【问题描述】:

我需要将属性值从 mvn 命令行导出到稍后我的 java 代码需要的文件。但我总是得到错误:

[ERROR] 未能执行目标 org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:write-project-properties 项目 MyApplication 上的(默认 cli):参数 'outputFile' 为目标 org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:write-project-properties 丢失或无效 -> [帮助 1] [错误]

这是我的项目结构

MyApplication
|src/main/java
|src/main/resources
|src/test/java
|src/test/resources
|lib          ////(no files here yet)
|pom.xml

而我的 pom.xml 是:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>write-project-properties</goal>
            </goals>
            <configuration><outputFile>${basedir}/lib/build.properties</outputFile>
            </configuration>
        </execution>
    </executions>
</plugin>

注意:我尝试在 lib 文件夹中手动创建空文件 build.properties,甚至出现同样的错误。也尝试使用插件版本 1.0.0。

【问题讨论】:

    标签: java maven maven-plugin


    【解决方案1】:

    好的,经过数小时尝试不同的组合,(moved &lt;configuration&gt; above/out of &lt;executions&gt;)in pom.xml,我现在看到创建了 lib/build.properties 文件。但是有人可以解释一下吗?

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>
                     <version>1.0-alpha-2</version>
                    <configuration>
                        <outputFile>${basedir}/lib/build.properties</outputFile>
                    </configuration>
                    <executions>
                        <execution>
                            <id>write-project-properties</id>
                            <goals>
                                <goal>write-project-properties</goal>
                            </goals>
                            <phase>test</phase>
                        </execution>
                    </executions>
                </plugin>
    

    【讨论】: