首页 > 解决方案 > 在 doLast 块中未获取 Gradle 项目属性最新值

问题描述

I have a problem picking up the right parameter values in the doLast method in my customer task

Example 

  I have a task loadfile as below

   

    task loadFile(type: JavaExec)
    
     {
                systemProperties = System.properties
                group = "Execution"
                main = "configurations.git.StreamYamlGitModule"
                classpath = sourceSets.test.runtimeClasspath
        jvmArgs = [
                "-DENV_NAME=${System.getProperty("env")}",
                ]
        }
        
        doLast {
            println (“Properites ${project.property(‘name’)}”)
        }

任务运行 java 类并将值填充到 gradle.properties 文件中

 gradle.properites 
   Name = test
   Strategy = abc

我遇到的问题是下面的代码没有填充加载到 name 属性的 gradle.properties 文件中的最新值。它总是拾取旧值(在任务运行之前。示例任务运行并将值“stage”填充到属性文件中,但它打印旧值“test”)

期望打印最新值的代码部分 doLast {

    println (“Properites ${project.property(‘name’)}”)
            }
    

Any idea how can I get the latest value printed ? appreciate your help

标签: build.gradle

解决方案


推荐阅读