Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting licenses on Android. #184

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

nic-bell
Copy link

@nic-bell nic-bell commented Apr 17, 2020

Licenses were always coming up blank on Android used some logic from oss-licenses-plugin.

Tested with following config in root build.gradle.

buildscript {
    ...
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        ...
        classpath "com.github.nic-bell:license-gradle-plugin:cac7e1c79a"
    }
}

allprojects {
    ...
    apply plugin: "com.github.hierynomus.license-report"
}

downloadLicenses {
    includeProjectDependencies = true
    dependencyConfiguration = 'releaseRuntimeClasspath'
}

Should fix #174 #182

@nic-bell nic-bell marked this pull request as ready for review April 17, 2020 12:16
@michallaskowski
Copy link

Hi. Any chance on replaying the job on CI, and merging? We tested the changes here, and it works on our Android project. We got 403 dependencies vs 0 with previous versions.

Copy link

@jakubvimn jakubvimn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great work and fixed the plugin for my Android project. All my comments are rather minor improvements that can be done in the code. I haven't found any serious problems.

build.gradle Outdated
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.1"
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:2.2.+'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use "+", specify concrete version

build.gradle Outdated
url "https://plugins.gradle.org/m2/"
jcenter()
repositories {
maven { url "https://plugins.gradle.org/m2/" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be replaced with gradlePluginPortal()

build.gradle Outdated
jcenter()
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://dl.google.com/dl/android/maven2/" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be replaced with google()

@@ -195,15 +245,48 @@ class LicenseResolver {
* @param conf Configuration
* @return whether conf is resolvable
*
* @see <a href="https://docs.gradle.org/3.4/release-notes.html#configurations-can-be-unresolvable">Gradle 3.4 release notes</a>
* @see <ahref="https://docs.gradle.org/3.4/release-notes.html#configurations-can-be-unresolvable" > Gradle 3.4 release notes</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

*/
protected boolean isTest(Configuration configuration) {
boolean isTestConfiguration = (configuration.name.startsWith(TEST_PREFIX) || configuration.name.startsWith(ANDROID_TEST_PREFIX))
configuration.hierarchy.each { isTestConfiguration |= TEST_COMPILE.contains(it.name) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the time there's no need to check the full hierarchy
return isTestConfiguration || configuration.hierarchy.any { TEST_COMPILE.contains(it.name) }

boolean isPackagedDependency = PACKAGED_DEPENDENCIES_PREFIXES.any {
configuration.name.startsWith(it)
}
configuration.hierarchy.each {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPackagedDependency |= configuration.hierarchy.any ...



boolean isDependencyIncluded(String depName) {
for (Pattern pattern : this.patternsToIgnore) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !patternsToIgnore.any { it.matcher(depName).matches() }

@nic-bell
Copy link
Author

nic-bell commented Jun 2, 2020

@jakubvimn I've made some changes based on your feedback.
I think upgrading the Android plugin and Gradle broke AnimalSniffer and maybe some of the tests too. Tried investigating this briefly then resorted to just using the plugin straight off JitPack.

@@ -97,14 +101,19 @@ license {
ignoreFailures true
}

animalsniffer {
excludeJars 'gradle-api-*'
ignoreFailures true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what it doesn't work. I've created an issue for Animals Sniffer
xvik/gradle-animalsniffer-plugin#22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that after animal sniffer update, this should not be needed anymore.

@@ -195,19 +245,46 @@ class LicenseResolver {
* @param conf Configuration
* @return whether conf is resolvable
*
* @see <a href="https://docs.gradle.org/3.4/release-notes.html#configurations-can-be-unresolvable">Gradle 3.4 release notes</a>
* @see <ahref="https://docs.gradle.org/3.4/release-notes.html#configurations-can-be-unresolvable" > Gradle 3.4 release notes</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahref -> a href

@jakubvimn
Copy link

@nic-bell will you look into the failed build? Do you need any support?

@Jeehut
Copy link

Jeehut commented Jun 30, 2020

@michallaskowski How did you get this running from the fork? Can you maybe provide some instructions and gradle code how you integrated it? Couldn't do it using jitpack following these instructions as this is not a library but a plugin. Some help would be much appreciated! @nic-bell

@michallaskowski
Copy link

@Jeehut I didn't, @jakubvimn did (we work together). I will ensure tomorrow he saw this message, in case he didn't get the notification. Afaik, he published a build from this PR's branch to our internal artifacts repository. I think we all count on this PR being merged, though.

@nic-bell
Copy link
Author

nic-bell commented Jun 30, 2020

@nic-bell will you look into the failed build? Do you need any support?

I gave up after I ran into the animal sniffer issue. I am not even sure this repo is actively maintained.

@nic-bell
Copy link
Author

@michallaskowski How did you get this running from the fork? Can you maybe provide some instructions and gradle code how you integrated it? Couldn't do it using jitpack following these instructions as this is not a library but a plugin. Some help would be much appreciated! @nic-bell

Hey the instructions to try it out are in the original PR description but here they are again anyway. I am using it in Android project as a library.

buildscript {
 ...
  dependencies {
    ...
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
    classpath "com.github.nic-bell:license-gradle-plugin:a1215e995d"
}

allprojects {
    ...
    apply plugin: "com.github.hierynomus.license-report"
}

downloadLicenses {
    includeProjectDependencies = true
    dependencyConfiguration = 'releaseRuntimeClasspath'
}

For the latest build look here:
https://jitpack.io/#nic-bell/license-gradle-plugin

@jakubvimn
Copy link

@Jeehut Yes, for our internal use, I just configured maven-publish plugin for our internal nexus and pushed the library there. But I guess that after the response from @nic-bell my help is not needed anymore.

@Jeehut
Copy link

Jeehut commented Jul 2, 2020

Thanks to @nic-bell's instructions I was able to set the fork up. But I'm still getting the output message:

No dependencies recognized!

Looks like this is not fixing #174, at least not for me ...

@Jeehut
Copy link

Jeehut commented Jul 2, 2020

Okay guys, taking back what I just said, it actually works now after I found the issue with @nic-bell's instructions:

In my project, I don't have a release variant, so I had to replace releaseRuntimeClasspath with productionReleaseRuntimeClasspath in my case, your case may vary. But it works now, thank you! 🎉

@jakubvimn
Copy link

Any update on that? Do you need any help to move it forward?

def configuration = project.configurations.getByName(dependencyConfiguration)
configuration.resolvedConfiguration.resolvedArtifacts.each { ResolvedArtifact d ->
String dependencyDesc = "$d.moduleVersion.id.group:$d.moduleVersion.id.name:$d.moduleVersion.id.version".toString()
if(isDependencyIncluded(dependencyDesc)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line does not work in new code, so it's not possible to exclude any project dependency

@Khosbayar
Copy link

May I know what is the status of this PR?
Seems like a lot of people are facing this issue.

Thanks and looking forward to it.

@Mepfic
Copy link

Mepfic commented Sep 21, 2021

Do we have any chance to look this PR merged? Because I faced with this issue too.. Thanks

@openkin
Copy link

openkin commented Sep 21, 2021

Do we have any chance to look this PR merged? Because I faced with this issue too.. Thanks

Use this version: https://github.com/openkin/license-gradle-plugin
(add to your project: implements "com.github.openkin:license-gradle-plugin:0d9582e233")

@Mepfic
Copy link

Mepfic commented Sep 21, 2021

0d9582e

I tried get it this way:
plugins { id "com.github.openkin:license-gradle-plugin" version "0d9582e233" },
but faced with error:
Plugin id contains invalid char ':'

Could you provide more details to implement it? Thanks for your time

@anikitin-intermedia
Copy link

anikitin-intermedia commented Sep 22, 2021

@Mepfic Try this:
Root build.gradle

buildscript {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath "com.github.openkin:license-gradle-plugin:0d9582e233"
    }
}

And then in your module build.gradle:

apply plugin: 'com.github.hierynomus.license-report'

@Mepfic
Copy link

Mepfic commented Sep 22, 2021

@Mepfic Try this:
Root build.gradle

buildscript {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath "com.github.openkin:license-gradle-plugin:0d9582e233"
    }
}

And then in your module build.gradle:

apply plugin: 'com.github.hierynomus.license-report'

In this case I get a error:
> Could not find com.github.openkin:license-gradle-plugin:0d9582e233. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/github/openkin/license-gradle-plugin/0d9582e233/license-gradle-plugin-0d9582e233.pom - https://repo.maven.apache.org/maven2/com/github/openkin/license-gradle-plugin/0d9582e233/license-gradle-plugin-0d9582e233.pom - https://plugins.gradle.org/m2/com/github/openkin/license-gradle-plugin/0d9582e233/license-gradle-plugin-0d9582e233.pom

Should I use some special repository?

@anikitin-intermedia
Copy link

@Mepfic Yes, use the jitpack. I've just updated the comment above

@Mepfic
Copy link

Mepfic commented Sep 22, 2021

In this case I get a error:
> Could not find com.github.openkin:license-gradle-plugin:0d9582e233. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/github/openkin/license-gradle-plugin/0d9582e233/license-gradle-plugin-0d9582e233.pom - https://repo.maven.apache.org/maven2/com/github/openkin/license-gradle-plugin/0d9582e233/license-gradle-plugin-0d9582e233.pom - https://plugins.gradle.org/m2/com/github/openkin/license-gradle-plugin/0d9582e233/license-gradle-plugin-0d9582e233.pom

Should I use some special repository?

@Mepfic Try this:
Root build.gradle

buildscript {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath "com.github.openkin:license-gradle-plugin:0d9582e233"
    }
}

And then in your module build.gradle:

apply plugin: 'com.github.hierynomus.license-report'

@Mepfic Yes, use the jitpack. I've just updated the comment above

Cool, I got license report, btw, in my case (for android) works fine only with next parameters:
downloadLicenses { includeProjectDependencies = true dependencyConfiguration = 'releaseRuntimeClasspath' }
Otherwise I got an empty report.
Thanks

@anikitin-intermedia
Copy link

@Mepfic Could you try dependencyConfiguration = 'all' ? This settings works in my case

@Mepfic
Copy link

Mepfic commented Sep 22, 2021

@Mepfic Could you try dependencyConfiguration = 'all' ? This settings works in my case

yea, it works too (from fork version). In release version 0.16.1 'all' didn't work, only 'releaseRuntimeClasspath' and 'debugRuntimeClasspath' - by my build variants.

@anthony-fresneau-kiplin

Hi,
Is that fix for Android will be merged and released soon?
Thanks and best regards,

@anthony-fresneau-kiplin
Copy link

Hello, Any updates on this pull request?
Regards

@conan
Copy link

conan commented Apr 25, 2024

The forked version worked for me on a test java project (not android). Any chance of this PR being merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report is empty (Android)