无法在gradle应用程序中设置系统属性

时间:2017-05-06 10:52:49

标签: gradle

我正在使用application插件来运行我的应用程序。我想像这样设置一个属性prop

-Dprop="some value"

为此,我在build.gradle

中添加了一行
applicationDefaultJvmArgs = ["-Dprop=$prop"]

我的build.gradle看起来像这样

apply plugin: 'application'

mainClassName='my.package.Main'

run {
    // allows to run application { gradle run -Pdocument=["file.xml"] }
    if (project.hasProperty("document")) {
        args groovy.util.Eval.me(document)
    }
}

dependencies {
    compile ("org.apache.poi:poi:$apachePoiVersion")
    compile ("org.apache.poi:poi-ooxml:$apachePoiVersion")
}

applicationDefaultJvmArgs = ["-Dprop=$prop"]

在我的Main应用程序中,我尝试显示它以检查它是否已设置

    try (ClassPathXmlApplicationContext context = 
            new ClassPathXmlApplicationContext("spring-context.xml")) {
        LOGGER.info("System property prop: [{}].", System.getProperty("prop"));

    }

但它显示System property prop: [null]。 我像这样启动应用程序

gradle run -Pprop="D://my-folder"

属性-Pdocument="['']"正常工作。有什么问题?

0 个答案:

没有答案