How to View Gradle module dependencies? - gradle

The following error occurs when gradle builds
Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
Go to the documentation to learn how to Fix dependency resolution errors.
So I found the following documentation:
link
But I can't find AppName > Tasks > android. I noticed the following tip:
So I opened the settings and unchecked the Do not build Gradle task list during Gradle sync
but this still doesn't work.

I already know the answer to this question, when you run the gradle command once, the interface will appear.
gradle app:dependencies

Related

Change default option of Intellij IDEA gradle plugin

Everytime I check out and open a project in Intellij I need to change the gradle plugin setting "Use Gradle from" from the default "'gradle-wrapper.properties' file" to "'wrapper' task in Gradle build script"
Is there a way in Intellij 2020 to make the shown option the default?
Reason I am asking: Generated gradle-wrapper files are not in our VCS, but the build.gradle is, and it has the wrapper task configured with the desired version. So when I check out a project, Intellij does not find gradle.properties (and neither can download gradle from web, as that is blocked). I then have to change the option "Use Gradle From" manually each time.
Another solution I tried is to automatically run a script when opening a module, which would run gradle wrapper with a fixed gradle version for the module, hence generating the missing wrapper files. But I find no possibility in Intellij to trigger that upon import..
It is not possible to change this setting for all projects. Please vote for this request: IDEA-215792.

Is there any way to get a "logical stacktrace" from Gradle?

I have a Gradle build that is failing because something is going wrong in one of the build steps. This particular step is not relevant to what I'm working on, and someone else is fixing it, but I'd rather not be held up waiting on them.
I've deleted the only reference to this step as a dependency of the core build in my build.gradle file... but it's still running! I tried running with the --stacktrace option, but all that gave me was a JVM stacktrace of Gradle's internal stack at the point where things failed, which is basically useless to me.
What I'd like is some actual useful information, a "stack trace" of the dependency chain that led to this step being included in the build process. Is there any way to get Gradle to give that to me?
I am guessing you want to see the dependency of tasks that will be executed.
In that case you could help yourself with using the following plugin https://gitlab.com/barfuin/gradle-taskinfo#gradle-taskinfo.
As such a graph is not provided out of the box from Gradle itself.
Include plugin
plugins {
id 'org.barfuin.gradle.taskinfo' version '1.0.5'
}
Then execute it to show task dependency tree (replacing task name with actual one)
./gradlew tiTree your_task_name

google errorprone java.lang.NoSuchMethodError

We are facing a strange problem. We are using net.ltgt.errorprone, version (0.0.8), along with guava(version 21) and gradle(version 3.1). Everything was working fine till today's morning. But suddenly all developers started getting this error
[system.err] An exception has occurred in the compiler (1.8.0_162). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NoSuchMethodError: com.google.common.base.Verify.verify(ZLjava/lang/String;Ljava/lang/Object;)V
at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:132)
We searched through internet, most of the solutions are related to guava, but there was no change in guava version or
errorprone or gradle since a long time. We tried running old code also, getting the same error. We are unable to understand root cause of the problem. Did anyone face the same problem?
com.google.collections:google-collections was renamed to com.google.guava:guava which is really annoying and can often lead to two versions of the library on the classpath.
Here's how I'd diagnose the problem
Run gradle dependencies in the "broken" build
Go back in history in source control (git?) until you have a working version
Run gradle dependencies in the "working" build
Look for differences in versions of com.google.collections:google-collections
Look for differences in versions of com.google.guava:guava
See here in the Gradle docs where guava rename is discussed
You might need to add this to build.gradle
dependencies {
modules {
module("com.google.collections:google-collections") {
replacedBy("com.google.guava:guava", "google-collections is now part of Guava")
}
}
}
A new version(2.3.0) of errorprone was released, this broke our build.
We find out the dependency using this command
./gradlew -q dependencyInsight --configuration errorprone --dependency error_prone_core
This clearly showed that latest version is being used. We fixed it by using a last workable version forcefully. Following lines were added to build.gradle file
configurations.all {
resolutionStrategy {
force 'com.google.errorprone:error_prone_core:2.2.0'
}
}

Tycho missing plugin when building an update site

When I build my project by tycho-maven-plugin, I encounter the following message:
[ERROR] Cannot resolve project dependencies:
[ERROR] Software being installed: foo-updatesite raw:0.2.0.'SNAPSHOT'/format(n[.n=0;[.n=0;[-S]]]):0.2.0-SNAPSHOT
[ERROR] Missing requirement for filter properties ~= $0: foo-feature.feature.group 0.2.0.qualifier requires 'foo-plugin 0.0.0' but it could not be found
[ERROR] Cannot satisfy dependency: foo-updatesite raw:0.2.0.'SNAPSHOT'/format(n[.n=0;[.n=0;[-S]]]):0.2.0-SNAPSHOT depends on: foo-feature.feature.group [0.2.0,0.2.1)
This error occurs when building an update site. Plugin and feature are build normally. I build the update site from PDE without issues.
The project structure is common: there is a parent project with pom packaging and three modules: plugin, feature and updatesite. Of course, I invoke mvn clean package from the parent project.
What can be the reason for this error? How can I debug it?
UPD: I tried many things: removed "grandparent" pom, removed SNAPSHOT/qualifier, played with configuration. However, I found the solution: I switched to tycho 0.19 instead of 0.21. So I suppose there is a bug in tycho 0.21.
The error message
Missing requirement for filter properties ~= $0
indicates that you have defined an environment filter when you include the plugin foo-plugin in the feature.xml. However this does not explain the dependency resolution error you are seeing. The only way I can reproduce the error message is by adding an Eclipse-PlatformFilter header in the manifest of the plugin using a value which doesn't match environments configuration in the POM.
I had the same error message:
Missing requirement for filter properties ~= $0: foo-feature.feature.group 0.2.0.qualifier requires 'foo-plugin 0.0.0' but it could not be found
For some reason this error (also) means, that foo-plugin is present... twice.
So in your case, open the "Content" tab of the "Target Editor" and make sure that foo-plugin is not present in two distinct versions. I common way this could happen is if two features contain the same bundle.

TeamCity Android Proguard results in "Your input classes appear to be inconsistent."

When I build my Android project from the command line with
gradlew assembleRelease
It works, but when I run it from my teamcity build agent the build gives a lot of warnings and fails witht he following errors:
[11:40:43][Step 4/10] Warning: there were 75 unresolved references to program class members.
[11:40:43][Step 4/10] Your input classes appear to be inconsistent.
[11:40:43][Step 4/10] You may need to recompile the code.
[11:40:43][Step 4/10] (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
[11:40:43][Step 4/10] :proguardRelease FAILED
I've tried modifying my build config to run gradlew from command line instead of using the gradle build runner but it is still broken. There is obviously something different between running the command from TeamCity versus running it manually through command line, but I don't know what that could be. Where to look?
Your problem and solution are right what it says on the tin:
Your input classes appear to be inconsistent.
You may need to recompile the code.
Given you're using Gradle, it's possible one version of gradle doesn't match the other or doesn't behave the same. This is particularly true if e.g. you've upgraded gradle from an older version.
Fix is simple: gradle clean or gradlew clean then try again.

Resources