简体   繁体   English

使用Gradle 5.x创建Jar和Tar

[英]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. 我正在为要迁移到其上的旧项目编写新的Gradle脚本。

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. 我最初是使用Gradle 4.x DSL编写脚本的,但我决定将其升级到5.x,以更好地进行将来的验证。

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. 我的任务之一是通过设置jar名称和扩展名以及在我的项目根目录的文件夹下创建一个新文件来创建jar。

When I migrated the script over to gradle 5.X the following properties have become deprecated: 当我将脚本迁移到gradle 5.X时,以下属性已被弃用:

baseName, extension, archiveName and destinationDir. baseName,扩展名,archiveName和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 我尝试过在线找到解决方案,但是还没有找到合适的方法或使用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: 到目前为止,我的脚本已执行此操作,这将创建tar,但不保留正确的文件层次结构:

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. 我的目标是制作一个包含文件夹bin,声音和类的tar。 Can anyone lend a hand in achieving this? 任何人都可以帮助实现这一目标吗?

  • baseName: The documentation shows that it's deprecated in favor of archiveBaseName baseName: 文档显示已弃用它,而推荐使用archiveBaseName
  • extension: The documentation shows that it's deprecated in favor of archiveExtension 扩展名: 该文档显示不推荐使用archiveExtension
  • archiveName: The documentation shows that it's deprecated in favor of archiveFileName archiveName: 该文档显示不推荐使用archiveFileName
  • destinationDir : The documentation shows that it's deprecated in favor of destinationDirectory destinationDir :文档显示不推荐使用它,而推荐使用destinationDirectory

There is no archiveDestinationDirectory property in Jar. Jar中没有archiveDestinationDirectory属性。 The documentation shows that the correct property is named destinationDirectory . 文档显示正确的属性命名为destinationDirectory

To include the directories themselves into the tar, you need to use, instead of what you're using: 要将目录本身包含到tar中,您需要使用而不是正在使用的内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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