如何停用gradle属性的缓存?

如何停用gradle属性的缓存?,gradle,caching,Gradle,Caching,根据用户的不同,将从文件加载不同的属性集 ext.userProps = new Properties(defaults.userProperties) file("env/configurations/user_${userName}.properties").withInputStream { userProps.load(it) } 用户运行第一次构建->一切正常 用户更改文件中的属性 再次运行生成->gradle仍使用旧属性 解决方法:每次更改属性文件后运行gradlew clean。

根据用户的不同,将从文件加载不同的属性集

ext.userProps = new Properties(defaults.userProperties)
file("env/configurations/user_${userName}.properties").withInputStream { userProps.load(it) }
  • 用户运行第一次构建->一切正常
  • 用户更改文件中的属性
  • 再次运行生成->gradle仍使用旧属性
  • 解决方法:每次更改属性文件后运行gradlew clean。然后它就如预期的那样工作了

    我如何直接告诉gradle不要缓存加载的属性


    编辑: 然后,这些属性用于替换配置文件中的字符串

    ext.dbconfig = ""
    ext.siteProps = new Properties(defaults.siteProperties)
    file("env/configurations/site_${siteName}.properties").withInputStream { siteProps.load(it) }
    
    ext.userProps = new Properties(defaults.userProperties)
    file("env/configurations/user_${userName}.properties").withInputStream { userProps.load(it) }
    
    ext.tokens = [
            // WEB-INF/web.xml
            smtpHostName              : "${siteProps.'mail.smtp.host'}".toString(),
            smtpPassword              : "${siteProps.'mail.smtp.password'}".toString(),
            hibernateSchemaCreation   : "${userProps.'hibernate.schema.creation'}".toString(),
            documentExportMode        : "${userProps.'document.exportMode'}".toString(),
            multipartConfigLocation   : "${siteProps.'multipartConfigLocation'}".toString(),
    
            // META-INF/context.xml">
            'hibernate.datasource.url': "${userProps.'hibernate.datasource.url'}".toString(),
            'hibernate.dialect' : "${userProps.'hibernate.dialect'}".toString(),
            'hibernate.connection.username' : "${userProps.'hibernate.connection.username'}".toString(),
            'hibernate.connection.password' : "${userProps.'hibernate.connection.password'}".toString(),
            'hibernate.connection.driver.class': "${userProps.'hibernate.connection.driver.class'}".toString(),
    ]
    

    问题在于,您正在使用外部数据来影响某些任务的执行结果,而不让Gradle知道。这将中断最新的检查

    查看,尤其是,它使您能够告诉现有的Gradle任务需要考虑其他输入

    一旦正确声明了所有输入,更改这些属性文件将导致Gradle重新执行相关任务


    因此,根据您的指示,您很可能希望增强
    processResource
    任务,该任务将在属性文件更改时正确运行。这将导致所生成的jar发生更改,从而导致测试重新运行等…

    问题在于您正在使用外部数据来影响某些任务的执行结果,而不让Gradle知道。这将中断最新的检查

    查看,尤其是,它使您能够告诉现有的Gradle任务需要考虑其他输入

    一旦正确声明了所有输入,更改这些属性文件将导致Gradle重新执行相关任务


    因此,根据您的指示,您很可能希望增强
    processResource
    任务,该任务将在属性文件更改时正确运行。这将导致生成的jar发生更改,从而导致测试重新运行,等等…

    您是否介意提供更多上下文?查看正在执行的任务将是有益的。您介意提供更多的上下文吗?查看正在执行的任务将是有益的。