【问题标题】:Gradle Distribution Task Output Files Not at Root of ZIPGradle 分发任务输出文件不在 ZIP 的根目录下
【发布时间】:2014-08-21 04:55:45
【问题描述】:

我创建了一个简单的 Gradle 构建,它将 ./src/main/groovy 的内容导出到一个 zip 文件。 zip 文件包含一个与 zip 文件同名的文件夹。我不知道如何使用分发插件将文件放入 zip 文件的根目录。

gradlew clean distZip 产生:

helloDistribution-1.0.zip -> helloDistribution-1.0 -> 文件

我想要什么:

helloDistribution-1.0.zip -> 文件

我的 build.gradle 文件:

apply plugin: 'groovy'
apply plugin: 'distribution'

version = '1.0'

distributions {
    main {
        contents {
            from {
                'src/main/groovy'
            }
        }
    }
}

我已尝试通过添加into { 'dir' } 来解决此问题,但无济于事。

【问题讨论】:

  • 这样不行。我想创建这种层次结构的唯一方法是使用普通的旧 ant zip 任务。

标签: gradle software-distribution


【解决方案1】:

要将文件复制到helloDistribution-1.0.zip -> helloDistribution-1.0 -> 的根目录下使用

contents {
    from {
        'some/file'
    }
    into ''
}

【讨论】:

    【解决方案2】:

    不幸的是,penfold 的回答对我不起作用。这是我想出的解决方案:

    task Package(type: Zip) {
    
        from {
            def rootScriptFiles = [] // collection of script files at the root of the src folder
            new File('src/main/groovy/').eachFile { if (it.name.endsWith('.groovy')) rootScriptFiles.add(it) }
    
    
            ['build/libs/',                 // build binaries
             'src/res/',                    // resources
             rootScriptFiles,               // groovy root source files
            ]
        }
        baseName = pluginName
    }
    

    【讨论】:

      【解决方案3】:

      使用into '/' 似乎可以解决问题:

      contents {
          from {
              'src/main/groovy'
          }
          into '/'
      }
      

      【讨论】:

      • 如果您只是更改 build.gradle 并调用 gradle distZip 您将看不到预期的效果。你必须打电话给gradle clean distZip
      猜你喜欢
      • 2016-08-20
      • 1970-01-01
      • 2015-10-26
      • 2018-03-23
      • 2022-01-21
      • 2018-08-24
      • 1970-01-01
      • 2016-10-21
      相关资源
      最近更新 更多