I'd like to define a Kodein-DI module in common Kotlin code (so I could import it from both JS and JVM modules).
What Gradle dependency should I add to commonMain?
My issue seems to be solved, see https://github.com/Kodein-Framework/Kodein-DI/issues/177#issuecomment-457915559 for details.
Related
I want to add kotlinx.coroutines to the command line compiler of the Kotlin so that i can import it without using gradle. For example I have a file Main.kt and no gradle tool for Kotlin. just look at mywindow. I tried search on YouTube, StackOverflow, reddit, Google and Github but it didn't solved my problem please help me out.
You will need to use the Kotlin compiler directly:
https://kotlinlang.org/docs/command-line.html
In addition, to use kotlinx.coroutines, you will need to have these JARs locally and add them to the classpath to the Kotlin compiler:
https://kotlinlang.org/docs/compiler-reference.html#classpath-path-cp-path
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")
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.
I have tried to build project in gradle with 3 modules, where:
1) module1 - common module with expect classes
empty build.gradle dependencies
2) module2 - common module with expect classes and with dependency from module 1:
build.gradle dependencies: compile project(':module1')
2) module3 - jvm platform module
build.gradle dependencies: expectedBy project(':module2')
When I try to compile a project, it appears errors in compilation stage of module3, that classes from module2 couldn't find classes from module1.
Kotlin 1.2.30
Gradle 4.6
Java 1.8_161
Does It possible to use multiple common modules together in one project? And does it possible to have expect classes in each common module?
Currently, using common declarations from multiple common modules is not supported, but it is planned for future versions.
In particular, once the fix for KT-22864 is released, it will allow you to add both module1 and module2 as expectedBy dependencies to module3. There's currently no public preview build with the fix, please stay tuned for 1.2.40 EAPs.
If you really want to try it early, you can use a dev build (e.g. 1.2.40-dev-754 from the https://dl.bintray.com/kotlin/kotlin-dev Maven repository).
You can also try a dev build of the IDE plugin (from here) to make the IDE import and analyze multiple expectedBy dependencies properly (1.2.30 can only import one such dependency).
For this it's needed to have more than one expectedBy declaration, which for now is forbidden. But, as say in kotlin slack, it will be possible soon.
So, for now, it's needed to switch to version 1.2.40-dev-754 of kotlin, and then it will be possible to add second expectedBy to dependencies in build.gradle in module3:
expectedBy project(':module1')
expectedBy project(':module2')
In the Kotlin documentation they are mentioning some kind of module for instance in the documentation for the internal modifier.
However I couldn't find any definition of the term module itself. So what is meant by module?
A module is a set of Kotlin sources compiled together:
an IntelliJ IDEA module;
a Maven project;
a Gradle source set;
a set of files compiled with one invocation of the Ant task.
This is in the same docs article about visibility modifiers. :)
From the Kotlin's documentation, a module is a set of Kotlin files compiled together:
an IntelliJ IDEA module
a Maven project;
a Gradle source set
a set of files compiled with one invocation of the <kotlinc> Ant task.
That is #hotkey's, but I would like to complement this answer.
According to Andrey Breslav, the Lead Language Designer of Kotlin:
a Kotlin module maps one-to-one to IntelliJ's module (iml-file).
According to IntelliJ's documentation:
Modules allow you to combine several technologies and frameworks in one application. In IntelliJ IDEA, you can create several modules for a project and each of them can be responsible for its own framework.
When it comes to a Maven project or a command line compilation, Andrey states:
Each compiler run, by default, is a separate module: all the binary dependencies will be treated as being not in the module being compiled at the moment.
Also, a Gradle source set is a module, with the exception that the test source set can access the internal declarations of main.
This means that if you have different build flavors in your Gradle configuration resulting in different source sets, for production and debug versions for example, then an internal class from one source set would not be available to be used in another source set.
Per Kotlin language specification ยง10.2 Modules:
A module is a concept on the boundary between the code itself and the
resulting application, thus it depends on and influences both of them.
A Kotlin module is a set of Kotlin files which are considered to be
interdependent and must be handled together during compilation.
In a simple case, a module is a set of files compiled at the same time
in a given project.
A set of files being compiled with a single Kotlin compiler invocation
A Maven module
A Gradle project
In a more complicated case involving multi-platform projects, a module
may be distributed across several compilations, projects and/or platforms.
For the purposes of Kotlin/Core, modules are important for internal
visibility. How modules influence particular platforms is
described in their respective sections of this specification.
I think you might be referring to org.koin.core.module.Module
A Koin module is a "space" to gather Koin definition. It's declared with the module function.
val myModule = module {
// Your definitions ...
}
This documentation would be helpful in that case.