nguyen tien
nguyen tien

Reputation: 11

How to write Kotlin class in one project and call this class in other Kotlin project (All in Kotlin)?

I am new to Kotlin and I am struggle with the designing of one Kotlin project that its classes and functions can be called from other Kotlin project. The language I use is pure Kotlin. What is the procedure to build such Kotlin project? (that its classes and functions call be called by other Kotlin project) And what procedure for project B to call classes and functions from project A? Thank you very much.

Upvotes: 1

Views: 236

Answers (1)

AndrewL
AndrewL

Reputation: 3390

Just the same as Java (where there will be a lot more online documentation). In short the brief process is

  1. You need to use a build system such as Maven or Gradle to compile and create the artefacts for project A. These are commonly distributed as a "jar" file which is really just a zip file with a special file extension and organisation of the classes within. You have to name to this artefact via the build system groupName artefactName version
  2. Then in the project B, using the build system again your reference that artefact groupName artefactName version. Secondly, inside the Project B code you import the package where the entry point is for your code

If you use an IDE like Eclipse or IntelliJ it will guide you through a lot of it. There are many tutorials... but I suggest you go looking first for java because of the very large number of tutorials/videos to choose from and then when you get that working start afresh with Kotlin

Upvotes: 3

Related Questions