Fix dependency info tasks (#47857)

We fixed warnings related to task input and outputs in #45098.
This particular input was not considered, a warning was present for it
and Gradle didn't use it as part of task inputs.
As soon as we fixed it Gradle started considering it an input and
enforced that it exists.

With this change we make it optional as the task can work both wih and
without this directory.
This commit is contained in:
Alpar Torok 2019-10-10 17:21:40 +03:00 committed by Jason Tedor
parent ec9198d0e2
commit 5cbc96ccb6
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
1 changed files with 4 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import org.gradle.api.internal.ConventionTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
@ -53,8 +54,9 @@ class DependenciesInfoTask extends ConventionTask {
Configuration compileOnlyConfiguration
/** Directory to read license files */
@Optional
@InputDirectory
File licensesDir = new File(project.projectDir, 'licenses')
File licensesDir = new File(project.projectDir, 'licenses').exists() ? new File(project.projectDir, 'licenses') : null
@OutputFile
File outputFile = new File(project.buildDir, "reports/dependencies/dependencies.csv")
@ -134,7 +136,7 @@ class DependenciesInfoTask extends ConventionTask {
protected String getLicenseType(final String group, final String name) {
File license
if (licensesDir.exists()) {
if (licensesDir != null) {
licensesDir.eachFileMatch({ it ==~ /.*-LICENSE.*/ }) { File file ->
String prefix = file.name.split('-LICENSE.*')[0]
if (group.contains(prefix) || name.contains(prefix)) {