0

The default-value of a Mojo property starts with:

${user.home}

I will write the value to a properties file and it should then be replaced at runtime not at build time.

I tried:

default-value="${user.home}/..."
default-value="\${user.home}/..."
default-value="\\${user.home}/..."

but it always gets replaced with the user.home of the user running the build.

Is there a way to avoid the replacement?

Edit:

The code in question is in a custom Maven Mojo:

public class MyCustomMojo extends AbstractMojo {

    ...

    /**
     * @parameter expression="${some-expression}" default-value="\\${user.home}/some-path"
     * @required
     */
    private String userdir;

    ...

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        ...

        Properties configProperties = new Properties();
        configProperties.setProperty(Main.USER_DIR_PROPERTY, userdir);
        Path propertiesFilePath = confPath.resolve(propertiesFileName);
        try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(propertiesFilePath))) {
            properties.store(bos, "");
        }

        ...

    }
}
4

1 回答 1

-1

在明确您正在谈论创建插件之后......关键是默认值旨在在mojo的构建执行期间被替换。我不确定你想达到什么目标,但我认为你在表达上误会了它。此外,默认值的想法是它将被替换,包括。系统属性。也许您可以提供补充信息以查看您想要实现的目标。

于 2012-05-12T02:22:14.267 回答