# Is it possible to partial override clean task?

**URL:** <https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100>\
**Category:** Old Forum Archive\
**Created:** [January 6, 2014, 6:51pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100 "2014-01-06T18:51:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cindy\_Woo](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Cindy\_Woo](https://discuss.gradle.org/u/Cindy_Woo)\
**Post date:** [January 6, 2014, 6:51pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/1 "2014-01-06T18:51:00Z")

</div>

I have multi-project build. I collecting all my generated jar in one place by redefined the destinationDir :

```gradle
tasks.withType(Jar) {
  //define directory where the archive is generated into
  destinationDir = "new/location"
  }

```

It’s working fine, but

the clean task doesn’t ‘know’ the new location. As result, the generated jar not cleaned by clean task. What is best solution for it? Can I partial override task? Or just create my new clean task?

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [January 6, 2014, 6:53pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/2 "2014-01-06T18:53:00Z")

</div>

Hello Cincy

you can configure additional custom locations to the clean task:

```gradle
clean{
    delete "new/location"
}

```

hope that helps.

cheers,

René

---

<div class="post-metadata">

**Author:** ![Cindy\_Woo](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Cindy\_Woo](https://discuss.gradle.org/u/Cindy_Woo)\
**Post date:** [January 6, 2014, 7:05pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/3 "2014-01-06T19:05:00Z")

</div>

☹

I got:

as a task with that name already exists or

Could not find method clean()

I’m using ‘clean’ task from java plugin. I would like use all that exit in it plus cleaning new location. How I can do it?

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [January 6, 2014, 7:14pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/4 "2014-01-06T19:14:00Z")

</div>

can you show your whole build.gradle file? “task with that name already exists” is likely thrown because you create a new task instead of configuring an existing one. ensure that the baseplugin (or the java plugin) is applied before adding the script above.

---

<div class="post-metadata">

**Author:** ![Cindy\_Woo](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Cindy\_Woo](https://discuss.gradle.org/u/Cindy_Woo)\
**Post date:** [January 6, 2014, 7:40pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/5 "2014-01-06T19:40:00Z")

</div>

build.gradle

```gradle
project(':antBuild').ext.antBuildFlag = true
  allprojects {
   project.ext.libDir = "$rootDir/lib/"
}
  configure(allprojects.findAll { it.hasProperty("antBuildFlag") == false } ) {
 //applying only for project that using java plugin
 apply from: "$rootDir/dep.gradle"
   }
    subprojects {
 tasks.withType(Jar) {
  //define directory where the archive is generated into
  destinationDir = file(libDir)
  }
}
      project(':A') {
 dependencies {
  compile rootProject.files(
  '${libDir}/abc.jar')
     }
}
    project(':B') {
 dependencies {
  compile project(':A')
 }
}
    project(':antBuild') {
 ant.importBuild 'build.xml'
    task build {
  dependsOn 'runbuild1'
//from build.xml
 }
}

```

$rootDir/dep.gradle

```gradle
apply plugin: 'java'
  sourceSets.main.java.exclude(' **/not_include/**')
    def currentJvm = org.gradle.internal.jvm.Jvm.current()
def gradleVersion = gradle.gradleVersion
  jar.manifest.attributes("Implementation-Title": "Gradle, v" + gradleVersion, "Created-By": currentJvm)
      dependencies {
 compile rootProject.files(
   ...
  )
 }

```

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [January 6, 2014, 11:41pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/6 "2014-01-06T23:41:00Z")

</div>

changing your subproject section in your build.gradle file should do the trick:

```gradle
...
subprojects {
    tasks.withType(Jar) {
        //define directory where the archive is generated into
        destinationDir = file(libDir)
        }
}
...

```

---

<div class="post-metadata">

**Author:** ![Cindy\_Woo](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Cindy\_Woo](https://discuss.gradle.org/u/Cindy_Woo)\
**Post date:** [January 7, 2014, 4:53pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/7 "2014-01-07T16:53:00Z")

</div>

Not sure what is difference between the section you quieted and mine…It’s same In this situation the ‘clean’ task is cleaning only build folder, but not the jar file

---

<div class="post-metadata">

**Author:** ![Cindy\_Woo](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Cindy\_Woo](https://discuss.gradle.org/u/Cindy_Woo)\
**Post date:** [January 8, 2014, 7:31pm UTC](https://discuss.gradle.org/t/is-it-possible-to-partial-override-clean-task/7100/8 "2014-01-08T19:31:00Z")

</div>

It’s work if add it to configure - since ant project doesn’t have property ‘clean’ :

```gradle
configure(allprojects.findAll { it.hasProperty("antBuildFlag") == false } ) {
 //applying only for project that using java plugin
        apply from: "$rootDir/dep.gradle"
          clean << {
   ....
  }
   }

```

Thank you for the help!
