How can I change the baseDir inside the applications Zip independently of the Archive name with Application Plugin?


(Ronald Brindl) #1

With ApplicationPlugin, I cannot change the baseDir inside the zipfile independently of the Archive name. I would like to have the baseDir without versionNumber, but the resulting Zip File name should have the version number included.

as the code in ApplicationPlugin.groovy suggests, this seems to be hardcoded:

def baseDir = { archiveTask.archiveName - ".${archiveTask.extension}" }
        archiveTask.into(baseDir) {
            with(pluginConvention.applicationDistribution)
        }

(Ronald Brindl) #2

I actually managed to fix this myself:

I access the rootspec of the AbstractArchiveTask and change its destDir by calling “into” on it.

tasks.withType(org.gradle.api.tasks.bundling.AbstractArchiveTask)*.with {
 rootSpec.into( { whateverItShouldBeNamed } )
}

(Ronald Brindl) #3

Solved it with a (somewhat dirty) workaround:

tasks.withType(org.gradle.api.tasks.bundling.AbstractArchiveTask).findAll { it.name.startsWith("dist") }*.with {
 def originalArchiveName=null
 doFirst {
  originalArchiveName = archiveName
  archiveName = applicationName + '-' + versionMajor + '.' + versionMinor + ( GUtil.isTrue(getExtension()) ? "." + getExtension() : "" )
 }
 doLast {
  def destDir = destinationDir
  copy {
   into destDir
   from archivePath
   rename archiveName, originalArchiveName
  }
  delete archivePath
 }
}

I would be glad if there was a cleaner solution