Why dagger requires to provide entities where I don't want to provide them? - kotlin

I have two modules - core and auth. In auth module I am trying to integrate Google Sign In to Firebase. All dependencies resolving correctly, but not a GoogleSignInClient. I don't want use dagger for this entity to provide this client somewhere. I want to use it only in this class. But dagger shows me an error :
class file for com.google.android.gms.auth.api.signin.GoogleSignInClient not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.google.android.gms.auth.api.signin.GoogleSignInClient not found
e: D:\Projects\<project path>\build\tmp\kapt3\stubs\internalProductionDebug\<class path>\di\components\AppComponent.java: error:
[ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.

Unfortunately it wasn't dagger problem. It happens with using several Android modules when you use api and implementation in gradle incorrectly.
I don't know why, but when I fixed my dependencies in Gradle - all become working.

Related

How does kotlin-gradle-plugin use 'kotlin.code.style' property?

The official Kotlin documentation states:
Add kotlin.code.style=official property to the gradle.properties file at the project root.
I'm trying to understand how kotlin-gradle-plugin handles this property.
Which gradle task uses it?
When running gradle build, I don't see my code being reformatted, even if I format my code badly on purpose.
I went through the Github source code of the plugin but couldn't properly get to understand it.
Thanks for your help.
Kotlin Gradle plugin doesn't use this property, as it's not responsible for reformatting the code. Instead, this property is used by Gradle importer of Kotlin plugin for IntelliJ IDEA.
This facade provides access to Gradle properties defined for the project:
https://github.com/JetBrains/kotlin/blob/v1.4.10/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/GradlePropertiesFileFacade.kt
It checks local.properties first in case user wants to override this value in the local configuration (this file is usually added to .gitignore for VCS to skip it during it's operations), then in usual gradle.properties.
Then the property gets consumed to configure the project here:
https://github.com/JetBrains/kotlin/blob/v1.4.10/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt#L158-L159
Same thing goes for Maven-based projects. These are the only two places the property is used throughout Kotlin repository apart from tests right now.

build.gradle.kts:10:28: Unresolved reference: settings

I have seen examples for using "by settings" delegation in build.gradle.kts scripts, but no matter what I have tried to do, Gradle complains that settings is an unresolved reference. If I change 'settings' to 'project', Gradle is happy. Has the use of 'by settings' been deprecated? I looked in the Gradle 6.4.1 manual and it shows this delegation. I've attached an image showing a simple Spring Boot app generated by Initializr with the only changes being the addition of the gradle.properties file and the delegation in the build.gradle.kts file. I'd really appreciate any hints about this issue... I know that I can use 'extra' properties or finding the property against the project object, but, frankly, this issue has annoyed me to the point that I need to know what is wrong! :P. Thank you for any help...
The project delegate is defined in the class ProjectDelegate. Your build script is evaluated against an instance of KotlinBuildScript which extends Project, so the delegate is available.
However, when settings.gradle is evaluated, projects aren't configured yet, so there's no instance of KotlinBuildScript. Instead, the script is evaluated against an instance of KotlinSettingsScript which extends Settings, which has the settings delegate. I don't think this delegate was ever available to project build scripts.
In both cases the delegate is provided by an extension function, because both Project and Settings are Java files part of the Gradle core API.
I hope that answers your question.

How to add dependencies to a kotlin library?

I am trying to build a kotlin library for discord bots, which can be found at https://github.com/TheDrone7/discord-kt , published to jcenter (bintray link - https://bintray.com/thedrone7/discordKt/discord-kt). The library has a few dependencies of it's own as well.
When I add my own library to my test app, the library's dependencies were not installed and I started getting some errors. Is there a way to specify the library's dependencies so that they get automatically installed when a user uses my library?
EDIT: -
So basically my test app's build.gradle.kts file's dependencies section is given below
dependencies {
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.theDrone:discordKt:0.0.1a")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
And my library is dependent on the following packages: -
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0
org.java-websocket:Java-WebSocket:1.4.0
com.beust:klaxon:5.0.5
org.slf4j:slf4j-jdk14:1.7.26
now when I run my test app, it shows gives error that there is no class named WebSocketClient which is a part of the org.java-websocket:Java-WebSocket:1.4.0 package and is also the base of my entire library.
When I add the listed packages to my test app's dependencies, it works perfectly fine. So is there a way that I could define in my library that the apps using it will also automatically depend on the packages my library depends on?
You declared the Java-WebSocket library as a dependency of your library using the implementation configuration.
This configuration means: I need that for my code to work, but it's an implementation detail and it's thus not part of my public API, so users of my library won't have access to it in their compile classpath.
So Gradle, when it generates the pom.xml file for your library, adds Java-WebSocket as a runtime dependency, and not as a compile dependency.
Read the java-library plugin documentation, which explains all of that in details. Once you have understood it, use api instead of implementation in your library's build.gradle.kts file for the dependencies that are part of your API, and should thus be compile dependencies and not runtime dependencies:
api("org.java-websocket:Java-WebSocket:1.4.0")

Migrating to non-experimental coroutines

I've been trying to migrate from the experimental version of coroutines (0.23.4) to the recently released one (1.0.1).
I also changed my version of Kotlin from 1.2.60 to 1.3.10.
I updated all of the import statements and removed the "experimental" bit from the gradle file.
When I try to compile my project, I get the following error:
Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class some.package.SomeClassName, unresolved supertypes: kotlinx.coroutines.CoroutineScope
SomeClassName doesn't even contain any reference to a coroutine -- it merely calls a method from a different module which in turn deals with some coroutines.
I tried adding the dependency on the coroutine packages to all of my gradle modules but that didn't help.
The only thing I found that describes a similar problem is this
but I can't understand how that would help or why my compilation fails anyway.
Any help please?
I had the same problem and it was happening because I was implementing the CoroutineScope in my "core" module and extending the class in the "app" module, which didn't have the coroutines import in build.gradle. Adding the import there as well fixed the problem.

Build error while compling sugar ORM

I am trying to compile sugar ORM to my application.But it is showing this build error.
Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.github.satyan:sugar:1.4.
How can I resolve it?Did I miss any other thing to add in gradle?
You need to change your app module's build.gradle file from:
implementation 'com.github.satyan:sugar:1.4'
to
implementation 'com.github.satyan:sugar:1.5'
Note: You may be using compile instead. This is now deprecated.
The current version can always be seen on the repo's page.