Java 在Gradle项目中加载外部属性文件,该文件可用于生成文件以及多项目应用程序

Java 在Gradle项目中加载外部属性文件,该文件可用于生成文件以及多项目应用程序,java,maven,gradle,Java,Maven,Gradle,我目前正在将一个Maven项目迁移到Gradle,我们使用下面的Maven插件读取Maven项目中的外部属性文件 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <version>1.0-alpha-2</version> <execu

我目前正在将一个Maven项目迁移到Gradle,我们使用下面的Maven插件读取Maven项目中的外部属性文件

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${user.home}/my_global.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>       

我想在Gradle中找到一种方法,这样只有对外部属性文件的引用才能让我在构建脚本和任何Java文件中获取它的键值对。

如果您正在从Maven过渡到Gradle,那么将类似的属性放入“~/.Gradle/Gradle.properties”。有关更多信息,请阅读发行版中的用户指南。

谢谢您的建议。我知道这种方法,但我想知道是否还有其他方法。也就是说,我需要像Gradle加载Gradle.properties文件一样加载属性文件。你现在找到更好的解决方案了吗?@RanilWijeyratne,在应用程序初始化期间,我目前正在使用java代码从
用户主页
读取属性文件。我不是用格拉德尔来读它的。
ext.extProgram = new Properties()
extProgram.load(new FileInputStream("${System.properties['user.home']}/my_global.properties"))

project.ext['any.plugin.property']=extProgram['property.in.external.file']