简体   繁体   中英

Creating Jar and Tar using Gradle 5.x

I'm writing up a new Gradle script for a legacy project being migrated over to it.

I originally wrote the script using Gradle 4.x DSL but I have decided to upgrade it over to 5.x for better future proofing.

One of my tasks was charged with creating the jar by setting the jar name and extension and creating a new file under a folder of my projects root directory.

When I migrated the script over to gradle 5.X the following properties have become deprecated:

baseName, extension, archiveName and destinationDir.

I have tried adjusting those to the new convention but I'm having issues with those properties being unable to be found:

Could not set unknown property 'archiveDestinationDirectory' for task ':jar' of type org.gradle.api.tasks.bundling.Jar."

I have tried finding a solution online to this but I have yet to find either a proper way to do it or an example that uses Gradle 5.x

Now the second question revolves around the notion of creating a tar. Again I have found no good example to show this. So far my script does this, which will create a tar but without preserving the correct file hierarchy:

task createTar(type: Tar) {
    archiveBaseName = 'info_tar'
    archiveExtension = 'gz'
    compression = Compression.GZIP
    from ('..') {
        include('bin/**')
        include('sounds/**')
        include('classes/**')
    }
    archiveFileName = archiveBaseName.get() + '.' + archiveExtension.get()
    //cleanup of temporary directories
    delete BIN_TARGET, SOUNDS_TARGET, CLASSES_TARGET
}

My goal is to produce a tar that contains the folders bin, sounds, classes. Can anyone lend a hand in achieving this?

  • baseName: The documentation shows that it's deprecated in favor of archiveBaseName
  • extension: The documentation shows that it's deprecated in favor of archiveExtension
  • archiveName: The documentation shows that it's deprecated in favor of archiveFileName
  • destinationDir : The documentation shows that it's deprecated in favor of destinationDirectory

There is no archiveDestinationDirectory property in Jar. The documentation shows that the correct property is named destinationDirectory .

To include the directories themselves into the tar, you need to use, instead of what you're using:

from('..') {
  include('bin/**')
  include('sounds/**')
  include('classes/**')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM