0

I'm using Gradle 2.7 on Windows 7. I have a properties file, "src/main/resources/liquibase.properties", whose properties I would like to reference in my build.gradle script. So for instance in my properties file I have

url=jdbc:mysql://localhost:3306/my_db
username=myuser
password=mypass

I would like to reference these in my script like so ...

liquibase {
  activities {
    main {
      changeLogFile 'src/main/resources/db.changelog-1.0.xml'
      url '${url}'
      username '${username}'
      password '${password}'
    }
  }
}

Also I would like to do this by just runing "gradle build" without having to specify any additional parameters on teh command line. How can I do this?

Thanks, - Dave

Dave
  • 15,639
  • 133
  • 442
  • 830
  • You should rather put a file liquibase.properties under project root. Then, this file can be used in build.gradle directly and should be used to filter (`ReplaceTokens`) a project properties file under `src/main/resources`. build.gradle shouldn't read project resources. – Opal Oct 15 '15 at 21:38

1 Answers1

1

You can load the properties file then get the values from that... Here is an example

liquibase {
  activities {
    main {
      File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")
      Properties properties = new Properties()
      properties.load(new FileInputStream(propsFile))
      changeLogFile 'src/main/resources/db.changelog-1.0.xml'
      url properties['url']
      username properties['username']
      password properties['password']
    }
  }
}
JBirdVegas
  • 10,855
  • 2
  • 44
  • 50