lg.lindstrom
lg.lindstrom

Reputation: 856

How to copy configuration files with Gradle

After build, I would like to copy a configuration file to a location outside of the project tree. This is my code:

task copyConfig(type:Copy) {
   from ( project.rootDir ) {
       include 'db.config'
   }
   into ( db_home + '\\config')
}
build.finalizedBy(copyConfig)

The property "db_home" are defined in gradle.properies and set to c:\db

I intended to copy the file db.config, placed in project root director, to c:\db\config.

Why does this not work?

Upvotes: 1

Views: 2143

Answers (1)

Stanislav
Stanislav

Reputation: 28106

Unfortunately, you didn't provide any info about the way how it doesn't work exactly. Whether the task is always UP-TO-DATE or it fails with exception, or it's executed though, but nothing happens.

At the moment, the most obvious reason for me, is that you may have a multiproject build and in that case project.rootDir would lead you to the most root of your project structure and if you have a configuration file within subproject, then you have to use projectDir variable, like so:

task copyConfig(type:Copy) {
   from ( projectDir ) {
       include 'db.config'
   }
   into ( db_home + '\\config')
}
build.finalizedBy(copyConfig)

Upvotes: 1

Related Questions