Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to skip a gradle task under some cases, which introduced by the bmuschko/gradle-docker-plugin?

$
0
0

I use the gradle plugin bmuschko/gradle-docker-plugin to integrate docker with gradle. I create some tasks in the build.gradle file:

    task copyJar(type: Copy) {    dependsOn build    from project.file("$project.buildDir/libs/"<< jarName)    into project.file("$project.buildDir/docker")}task createDockerfile(type: Dockerfile) {    dependsOn copyJar    // Generate Dockerfile}task buildDockerImage(type: DockerBuildImage) {    dependsOn createDockerfile    inputDir = createDockerfile.destFile.parentFile    tag = 'example.com/'<< jar.baseName    if (project.hasProperty('imageTag')) {        tag += ':'<< imageTag    }}task pushDockerImage(type: DockerPushImage) {    dependsOn buildDockerImage    conventionMapping.imageName = { 'example.com/'+ jar.baseName }    if (project.hasProperty('imageTag')) {        conventionMapping.tag = { imageTag }    }}

What I want is when I run gradle pushDockerImage, if there is no change in the source code this task could be skipped. However, now each time I run the gradle pushDockerImage, it will be executed and last a long time to push the image to the docker registry.

I also run gradle --info pushDockerImage two times, the second time gradle shows the following infomation:

Skipping task ':core/sample:buildDockerImage' as task onlyIf is false.:core/sample:buildDockerImage SKIPPED:core/sample:buildDockerImage (Thread[main,5,main]) completed. Took     1.765 secs.:core/sample:pushDockerImage (Thread[main,5,main]) started.:core/sample:pushDockerImageExecuting task ':core/sample:pushDockerImage' (up-to-date check took 0.001 secs) due to:    Task has not declared any outputs.

So here buildDockerImage is skipped, but pushDockerImage is not. How can I also skip it?


Viewing all articles
Browse latest Browse all 12111

Trending Articles