Home > Blockchain >  How do I copy something into the parent directory of my build.gradle?
How do I copy something into the parent directory of my build.gradle?

Time:12-15

How can I copy FileA into Dir2? Assuming FileA is created with a gradle build?

Parent
- Gradle Proj
    - build.gradle
    - FileA
-Dir2
-Dir3

CodePudding user response:

You can define your own task to do so

task copyDocs(type: Copy) {
    from './fileA'
    into './Dir2'
}
tasks.named("build") { finalizedBy("copyDocs") }

This will do the copy when the task named "build" is finished .

And you can also use the afterEvaluation i think . For more info about you can check the official docs .

for example

allprojects {
    afterEvaluate {
        task copyDocs(type: Copy) {
            from './fileA'
            into './Dir2'
        }
    }
}

CodePudding user response:

After some research I managed to find $rootDir which targets the root directory of the project.

This made it easy to copy eg:

task copyDocs(type: Copy) {
    from '$projectDir/FileA'
    into '$rootDir/Dir2'
}
  • Related