diff --git a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy index 6446ef2..b2b74d0 100644 --- a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy +++ b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy @@ -468,9 +468,28 @@ class BallerinaPlugin implements Plugin { } project.tasks.register('clean', Delete.class) { - delete "$project.projectDir/target" - delete "$project.projectDir/build" - delete "$project.rootDir/target" + doLast { + if (buildOnDocker) { + project.exec { + def deleteUsingDocker = """ + docker run --user root \ + -v $parentDirectory:/home/ballerina/$parentDirectory.name \ + -v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \ + ballerina/ballerina:$ballerinaDockerTag \ + /bin/sh -c "cd $parentDirectory.name/$projectDirectory.name && rm -rf build target" + """ + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "$deleteUsingDocker" + } else { + commandLine 'sh', '-c', "$deleteUsingDocker" + } + } + } else { + delete "$project.projectDir/target" + delete "$project.projectDir/build" + } + delete "$project.rootDir/target" + } } }