本文介绍了将生成的第三方许可证复制到资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



配置


  • Gradle 2.x

  • license-gradle-plugin 0.11.0



代码:

 任务beforeAssemble(dependsOn:assemble) << {
downloadLicenses.execute()
CopyToAssetsTask.execute()
}

任务CopyToAssetsTask(类型:复制){
description ='生成的副本第三('$ buildDir / reports / license'){
包括('dependency-license.html')
}
到'$ buildDir / intermediates'中的资产
/ assets / debug / legal'
}

apply plugin:'license'

downloadLicenses {
includeProjectDependencies = true
reportByDependency = true
reportByLicenseType = true
dependencyConfiguration =compile
}

在命令行中:
gradlew clean assembleDebug



结果APK不包含生成的文件,因为I希望。我对Gradle很陌生,所以也许有一个简单的解释?

解决方案

这个解决方案适用于我, Johan Stuyts发布的答案版本。



一个限制:生成的报告将最终存储在根资产文件夹中,而不是预期的子文件夹合法。

  buildscript {
// ...
依赖项{
// ...
classpath'nl.javadude.gradle .plugins:license-gradle-plugin:0.11.0'
}
}

android {
// ...

//将许可插件的输出文件夹添加为
//资源的源文件夹。
sourceSets {
main {
// ...
assets.srcDirs = ['src / main / assets','build / reports / license']
}
}
}

downloadLicenses {
includeProjectDependencies = true

reportByDependency = true
reportByLicenseType = false

report.html.enabled = true
report.xml.enabled = false

dependencyConfiguration =compile
}

//在项目评估后添加一个依赖项,因为
// Android插件不会将任务merge * Assets添加到
中//立即项目。
project.afterEvaluate {
//合并
//资产时(实际上:就在此之前)下载许可证(对于debug和
//发布构建类型)。

//如果添加/更改构建类型,则必须添加/更改
//这些任务名称。
mergeDebugAssets.dependsOn project.tasks.getByName('downloadLicenses')
mergeReleaseAssets.dependsOn project.tasks.getByName('downloadLicenses')
}


I want to automate inclusion of the latest generated third party licenses in Gradle.

Config:

  • Gradle 2.x
  • license-gradle-plugin 0.11.0

Code:

task beforeAssemble(dependsOn: assemble) << {
    downloadLicenses.execute()
    CopyToAssetsTask.execute()
}

task CopyToAssetsTask(type: Copy) {
   description = 'Copies generated Third Party Licenses into assets'
   from('$buildDir/reports/license') {
      include('dependency-license.html')
   }
   into '$buildDir/intermediates/assets/debug/legal'
}

apply plugin: 'license'

downloadLicenses {
    includeProjectDependencies = true
    reportByDependency = true
    reportByLicenseType = true
    dependencyConfiguration = "compile"
}

In command line:gradlew clean assembleDebug

The resulting APK does not include the generated file as I was hoping. I'm quite new to Gradle so maybe there is a simple explanation?

解决方案

This solution worked for me and is a slightly modified version of the answer that Johan Stuyts posted.

One limitation though: The generated report will end up in the root assets folder instead of the intended subfolder "legal".

   buildscript {
       // ...
       dependencies {
          // ...
          classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
      }
   }

   android {
   // ...

   // Add the output folder of the license plug-in as
   // a source folder for assets.
      sourceSets {
          main {
              // ...
              assets.srcDirs = ['src/main/assets', 'build/reports/license']
          }
      }
   }

   downloadLicenses {
      includeProjectDependencies = true

      reportByDependency = true
      reportByLicenseType = false

      report.html.enabled = true
      report.xml.enabled = false

      dependencyConfiguration = "compile"
   }

   // Add a dependency after the project has been evaluated, because
   // the Android plug-in does not add tasks "merge*Assets" to
   // the project immediately.
   project.afterEvaluate {
      // Download the licenses when (actually: just before) the
      // assets are merged (for both the "debug" and the
      // "release" build types).

      // If you add/change build types, you have to add to/change
      // these task names.
      mergeDebugAssets.dependsOn project.tasks.getByName('downloadLicenses')
      mergeReleaseAssets.dependsOn project.tasks.getByName('downloadLicenses')
   }

这篇关于将生成的第三方许可证复制到资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:43