How redefine the directory where generated JAR files (libsDirName)?


(dusiabh) #1

I have multi-project buld. I need all my jar be in one directory: build/New_libs What is correct definitions for that? That one created the jar under proj1/proj2/foo1/build/libs/

//settings.gradle:
//----------------------------
include 'foo1', 'foo2'
project(":foo1").projectDir = new File (settingsDir, "proj1/proj2")
      //build.gradle
//---------------------------
  subprojects {
 apply plugin: 'java'
 rootProject.libsDirName = '${rootProject}.build.New_libs'
 println "rootProject.libsDirName = ${libsDirName}"
}

Thank you very much for your help!


(Peter Niederwieser) #2

‘libsDirName’ is relative to the project’s base directory, and thus cannot be used for this purpose. You’ll want something like:

subprojects {
    apply plugin: 'java'
    tasks.withType(Jar) {
        destinationDir = file("$rootDir/build/New_libs")
    }
}

(dusiabh) #3

Thank you! It’s help!


(dusiabh) #4

If I redefine the destination dir, the task clean 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?


(Peter Niederwieser) #5

By default, the ‘clean’ task deletes the ‘build’ directory, but it can be reconfigured as needed (see the ‘Delete’ task type in the Gradle Build Language Reference). Another option is to keep separate output directories and add another task that copies Jars into a common directory.


(Peter Niederwieser) #6

Please don’t ask the same question twice (http://forums.gradle.org/gradle/topics/is_it_possible_to_partial_override_clean_task). Thanks.