Closed szugyi closed 2 years ago
I was running into the same problem when I opened issue #22. Unfortunately the issue got somewhat sidetracked, and was ultimately closed after I enabled task configuration. It probably should have been renamed or left open.
I played around at length trying to do exactly what you're doing. It seems that for some reason the dependencies haven't been resolved when the license task is bring run, so you're getting empty outputs. I was never able to determine which tasks the license task needs to run after.
Thank you for the quick response! It would be really useful if we could make the plugin generate the report on every build.
Yeah, it would really help for CI and CD.
I was just having a look at the Open Whisper Systems' Witness Plugin. It seems they're using afterEvaluate
to execute a task after the dependencies have been resolved. I'm going to set up a test project to see if I can do something similar.
Looks like anything involving afterEvaluate
will have to be done at the plugin level, just like in the link I posted above. @jaredsburrows thoughts?
@MatthewTamlin Wasn't #22 your issue that you solved by PR #30?
@szugyi It used to generate after every build, I believe. I believe that #30 may have changed that?
@jaredsburrows I have just checked out the 0.8.0 version which does not contain the changes from the mentioned PR, but unfortunately the generated reports are also empty if I just run the assembleDebug task. It contains the license info of the dependencies only if I run the licenseReport task individually.
@szugyi @MatthewTamlin The reason I do not run after every build is because I do not want to potentially slow down other's builds. If you want to run the license report for updated license results then you can do so and add it to your SCM. Maybe I can look into running it after each build.
@jaredsburrows Yes, that is how we use the plugin currently, but this can be forgotten easily, especially in a big team to run it every time a dependency is added, updated or removed.
@szugyi Would you want to make a PR for this?
@jaredsburrows Unfortunately, I don't think I will have the time for this anytime soon.
This should be easy to do. I will look into it tomorrow.
Thanks!
After upgrade android gradle plugin to 3.2.0, license file became empty. Also, another one in build/reports/ license
is empty as well. During debugging I found, somehow dependencies can't be resolved, if license generation task depends on another build task.
However, launching manually ./gradlew licenseReleseReport assembleRelease
works.
For anyone still struggling with this:
I've switched to https://developers.google.com/android/guides/opensource which works just fine.
Hint: You might want to add a theme to the activities of this library like so (e.g. when using a launcher theme or one without an actionbar):
<activity android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"/>
<activity android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"/>
This should be easy to do. I will look into it tomorrow.
Hi @jaredsburrows any update? Thanks!
I recently updated the tests. This will make adding features and fixing bugs easier. Thanks for the bump.
Jared Burrows
jaredsburrows@gmail.com jaredsburrows@gmail.com LinkedIn: https://www.linkedin.com/in/jaredsburrows
On Fri, Feb 8, 2019 at 11:18 AM darrengyles notifications@github.com wrote:
This should be easy to do. I will look into it tomorrow.
@jaredsburrows https://github.com/jaredsburrows any update? Thanks.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jaredsburrows/gradle-license-plugin/issues/38#issuecomment-461914665, or mute the thread https://github.com/notifications/unsubscribe-auth/ABqMSDTcu_1ryJ_G31Gs6QNxH95fM-Y8ks5vLc16gaJpZM4S79IV .
I was having similar issues to this. I played around with the LicenseTask (dropping it in my buildSrc and hacking away), and it looks like the issue is lenientConfiguration hides some conflicts:
set.resolvedConfiguration.lenientConfiguration.artifacts.forEach { artifact ->
When I changed this to use resolvedConfiguration.resolvedArtifacts
, I see the submodule conflicts that lenientConfiguration was skipping:
> Could not resolve all dependencies for configuration ':app.bsp:implementation'.
> Could not resolve project :framework.core.
Required by:
project :app.bsp
> Cannot choose between the following variants of project :framework.core:
- debugRuntimeElements
- releaseRuntimeElements
All of them match the consumer attributes:
- Variant 'debugRuntimeElements' capability mantis:framework.core:unspecified:
- Unmatched attributes:
- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Found org.gradle.usage 'java-runtime' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
- Variant 'releaseRuntimeElements' capability mantis:framework.core:unspecified:
- Unmatched attributes:
- Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Found org.gradle.usage 'java-runtime' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
// and many more...
Gradle dependency resolution not being my area of expertise, I kinda hacked around it a bit by adding to my gradle file to set up configuration sets to focus on release jars for disambiguation:
def releaseType = project.getObjects().named(BuildTypeAttr.class, "release")
configurations {
licenseApi {
extendsFrom releaseApi
attributes {
attribute(AndroidArtifacts.ARTIFACT_TYPE, "jar")
attribute(BuildTypeAttr.ATTRIBUTE, releaseType)
}
}
// and similar for licenseCompile and licenseImplementation
}
and then back in the plugin
val compile = configurations.findByName("compile")
val api = configurations.findByName("api")
val implementation = configurations.findByName("implementation")
val licenseCompile = configurations.findByName("licenseCompile")
val licenseApi = configurations.findByName("licenseApi")
val licenseImplementation = configurations.findByName("licenseImplementation")
// copy the real deps into my helper configs
compile?.dependencies?.let { licenseCompile?.dependencies?.addAll(it) }
api?.dependencies?.let { licenseApi?.dependencies?.addAll(it) }
implementation?.dependencies?.let { licenseImplementation?.dependencies?.addAll(it) }
fun addDep(artifact: ResolvedArtifact) {
val id = artifact.moduleVersion.id
pomDependencies.add(project.dependencies.add(pomConfiguration, "${id.group}:${id.name}:${id.version}@pom"))
}
licenseCompile?.resolvedConfiguration?.resolvedArtifacts?.forEach(::addDep)
licenseApi?.resolvedConfiguration?.resolvedArtifacts?.forEach(::addDep)
licenseImplementation?.resolvedConfiguration?.resolvedArtifacts?.forEach(::addDep)
Obviously this is waaaay specific to my use case, nowhere near general enough for your plugin, but I thought it might help diagnosis...
I'm sure someone much more familiar with gradle internals would have a simpler solution
I tested this locally:
tasks.whenTaskAdded {
if (name == "assembleDebug") {
dependsOn("licenseDebugReport")
}
}
tasks.whenTaskAdded {
if (name == "assembleRelease") {
dependsOn("licenseReleaseReport")
}
}
I have tried to generate reports every time the project is built, but in case I add the LicenseReport task to run before another task both the generated html and json files are empty. As I can see in the discussion in issue #22 it should be possible since version 0.8.1.
If I run the task individually with
./gradlew licenseDebugReport
the generated files contain all the dependencies I have. However if I run the./gradlew assembleDebug
I can see in the logs that the task was run, and it prints that the reports were generated, but they are empty.@MatthewTamlin Can you see what the problem might be with my configuration?
log:
My configuration: Project level
build.gradle
App module
build.gradle
output
open_source_licenses.html
output
open_source_licenses.json
[]