I want to create a task in my root project that will create a custom TAR for some subprojects.
task archive(type: Tar) {
project.logger.info("Tar bundle :: ")
baseName = project.baseName
destinationDir = new File(project.buildDir.path)
archiveDir = new File(project.buildDir.path)
compression = Compression.GZIP
from (archiveDir)
}
I have found this task but what I need, is a subproject to send in the subproject.name and have the task use the buildDir and the source dir from the subproject calling the task. Then save the archive to /target of the subproject as well.
Is this possible without creating a new task for each subproject?
If every subproject is supposed to create its own Tar, then you need to create one task per subproject. This is as easy as wrapping the task declaration in
subprojects { ... }. You’ll also have to remove all occurrences ofproject.from your code, plus the wholebaseNameline. (All of this is redundant anyway.)new File(project.buildDir.path)is the same asbuildDir. Instead oflogger.info("Tar bundle :: "), you probably wantdoFirst { logger.info("Tar bundle :: ") }. Otherwise, this message will get logged for each and every build, no matter which tasks get executed.