美文网首页逝者如斯
gradle build文件多环境配置

gradle build文件多环境配置

作者: 福克斯记 | 来源:发表于2017-04-24 22:46 被阅读26次

    build.gradle

    task printProps << {
        println "db.url:  $config.database.url"
        println "db.user: $config.database.user"
        println "db.password:   $config.database.password"
        println "db.dbname:   $config.database.dbname"
    }
    
    def loadConfiguration() {
        def environment = hasProperty('env') ? env : 'dev'
        project.ext.environment = environment
    
        def configFile = file('config.groovy')
        def config = new ConfigSlurper(environment).parse(configFile.toURI().toURL())
        project.ext.config = config
    }
    

    同目录下,config.groovy

    environments {
        dev {
            database {
                url = "jdbc:mysql://127.0.0.1/"
                user = "root"
                password = ""
                dbname = "diamond"
            }
        }
    
        test {
            database {
                url = ""
                user = ""
                password = ""
                dbname = ""
            }
        }
    
        prod {
            database {
                url = ""
                user = ""
                password = ""
                dbname = "bizdb"
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:gradle build文件多环境配置

        本文链接:https://www.haomeiwen.com/subject/iolmzttx.html