license-gradle-plugin icon indicating copy to clipboard operation
license-gradle-plugin copied to clipboard

licenseTest fails if no HEADER set, default HEADER file does not exist, and ignoreFailures=true

Open nkoterba opened this issue 9 years ago • 12 comments

First, great plugin! Thanks for all the effort and hard work.

Second, while we may eventually utilize the primary purpose of this plugin (apply licenses as headers to source files), we're most interested in the dependency and license management (via the downloadLicenses task).

We tried configuring the license plugin as follows:

license {
        exclude "**/*"
        skipExistingHeaders true
        ignoreFailures true
}

Unfortunately, our gradle build fails because licenseTest task tries to use the default header value (LICENSE) but that file does not exist:

:code:configs:licenseTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':code:configs:licenseTest'.
> File '/code/configs/LICENSE' specified for property 'header' does not exist.

The error is valid...we do NOT have a LICENSE file in /code/configs. But we assumed that excluding everything (exclude "*/") OR setting ignoreFailures=true, the licenseTest task would continue.

We were able to workaround this issue, by creating an empty LICENSE file at the root location and setting the header property:

    license {
        header rootProject.file('LICENSE')
        exclude "**/*"
        skipExistingHeaders true
        ignoreFailures true
    }

However, we also contemplated configuring our gradle to always skip the licenseMain, licenseTest, etc. tasks.

So:

  1. Should 'ignoreFailures' ignore all failures, including HEADER file not existing
  2. If not, how would you suggest getting past the licenseTest task:
  • Set a dummy header property like we did above OR
  • Configuring gradle to always ignore/exclude licenseTest and licenseMain tasks since we are mainly interested in downloadLicenses task.

Thanks!

nkoterba avatar Jul 29 '15 23:07 nkoterba

Actually I think the correct one would be the last option you suggest. Disabling the licenseTest and licenseMain tasks.

Ignoring the non-existing HEADER file would actually potentially trip up people when they by accident configure it wrongly, or when they do not have access to the URI specified by the headerURI property. Setting a dummy would work, but I think the clearest at the moment would be to exclude the tasks.

I could also introduce some more flags such as checkLicenseHeaders and/or downloadLicenses that would tweak which tasks are active?

hierynomus avatar Aug 03 '15 12:08 hierynomus

@hierynomus Whatever is the easiest/simplest option to implement that would allow us to disable licenseChecking would work for us.

Since we currently don't use licenseTest and licenseMain, having an option to completely "disable" them may also speed up our gradle tasks.

nkoterba avatar Aug 10 '15 15:08 nkoterba

Thanks for this plugin!

I am having the same issue and would love to be able to not have the license tasks get created.

mikegehard avatar Nov 10 '15 20:11 mikegehard

This is a great plugin!

As the others, I mostly use the downloadLicenses task, so an option to disable other tasks would be greatly appreciated.

ghost avatar Nov 30 '15 12:11 ghost

I think things go wrong already when this plugin hooks into the regular build. Wouldn't it be better to just offer the tasks, and then let users hook them into their Gradle builds as they see fit?

Doing the other way around is much more awkward. I could not find a way to disable these tasks in a multi-project gradle build where the plugin is applied for all sub-projects.

tfnico avatar Dec 04 '15 11:12 tfnico

I think that's a matter of taste. If you apply the Java plugin, you don't expect you're needing to wire up all the compile/resources/test tasks yourself. Same holds here. I think however the plugin should be split in two, one the license-enforcing/formatting plugin, and a license-reporting plugin. This would allow you to choose which one of the two you want.

hierynomus avatar Dec 04 '15 12:12 hierynomus

basic gladle solution: licenseMain.onlyIf { rootProject.file('LICENSE ').exists() }

dyoniziak avatar Jan 02 '17 11:01 dyoniziak

This worked for me:

gradle.startParameter.excludedTaskNames += "licenseMain"
gradle.startParameter.excludedTaskNames += "licenseTest"

But I think these task should not be activated just by adding this plugin.

HaVonTe1 avatar Mar 23 '17 12:03 HaVonTe1

For all the changes mentioned above, where should they be applied? In the Build.Gradle file? Some where else?

Fady-Guirguis avatar Feb 19 '18 18:02 Fady-Guirguis

Is there still no workaround other than to explicitly exclude the above tasks?

sadeel avatar Sep 10 '18 18:09 sadeel

Looks like the plugin was split in two a couple of years back (https://github.com/hierynomus/license-gradle-plugin/commit/6ca08d50a2f797a7d29ef3518fc05c116f8a2832) albeit within the same repository, and therefore with the same plugin id. This means you can now opt out of applying the LicenseBasePlugin and just use the LicenseReportingPlugin using the following build.gradle snippet:

plugins {
  id "com.github.hierynomus.license" version "0.15.0" apply false
}

// com.github.hierynomus.license contains 2 plugins, we just want this one applied:
apply plugin: com.hierynomus.gradle.license.LicenseReportingPlugin

Still seems pretty ugly to me - would much prefer two separately identified plugins - but it appears to do the job.

roxspring avatar May 13 '19 12:05 roxspring

Thanks for this information.

mousumi8 avatar Jun 19 '20 18:06 mousumi8