Jordi
Jordi

Reputation: 23187

Execute one gradle task

I've this two tasks:

war {
    webInf { from 'src/main/resources/WEB-INF' }
    manifest {
        attributes 'Implementation-Version': versioning.info.display
    }
}

task createDemoWar(type: War, dependsOn: classes) {
    archiveName "webapi-demo-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    copy {
        from 'scopes'
        include 'configuration.demo.properties'
        into 'src/main/resources/'
    }
}

task createDevelopmentWar(type: War, dependsOn: classes) {
    archiveName "webapi-dev-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    copy {
        from 'scopes/'
        include 'configuration.development.properties'
        into 'src/main/resources/'
    }
}

Both tasks are trying to copy a property file fromscopes folder to src/main/resources/ folder.

I only run one task, however two files are copied in src/main/resources/ (configuration.demo.properties and configuration.development,properties.

Any ideas?

Upvotes: 1

Views: 189

Answers (1)

Stanislav
Stanislav

Reputation: 28096

You use two copy specifications at the configuration phase (note, copy specification in that case doesn't configure your task, but add some extra action to it's configuration). That means, your files are getting copied during configuration. That's all because of this:

copy {
    ...
}

You have to run it during execution, to do that, try to move it into the doLast or doFirst closure, like so (for both tasks):

task createDemoWar(type: War, dependsOn: classes) {
    archiveName "webapi-demo-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    doFirst {
        copy {
            from 'scopes'
            include 'configuration.demo.properties'
            into 'src/main/resources/'
        }
    }
}

In that case, files will be copied only if task will be executed, right before the execution.

Upvotes: 1

Related Questions