Skip to content

Kotlin Support #722

Open
Open
@Jaimss

Description

@Jaimss

Hi, I love using this plugin to setup my minecraft plugin projects. In the past I have always used Java, but recently, I switched to Kotlin because I personally like it more and I think it is better.

Would it be possible to add Kotlin support to the options when setting up a project?

Activity

DenWav

DenWav commented on Jun 16, 2020

@DenWav
Member

Maybe, depends on when Jetbrain's multi JVM language API work truly gets to a point when it can support it. The issue now is any features written for Java don't work for Kotlin, though that should be changing / is changing due to new API changes Jetbrains is working on. If it's to the point where mcdev features work or only require minor changes to work then it's something to consider possibly.

Jaimss

Jaimss commented on Jun 16, 2020

@Jaimss
Author

Alright. It’s not too big of a deal. I just have to recreate my main class as a kotlin class and add maven dependencies for kotlin to set it up, but if it could be automatic, that would we awesome!

SmushyTaco

SmushyTaco commented on Jul 6, 2020

@SmushyTaco

+1

TheFruxz

TheFruxz commented on Aug 25, 2020

@TheFruxz

Problem? NO!

I don't see a problem in using Kotlin on a bukkit server, because libraries from e.g. https://dev.bukkit.org/projects/kotlin are adding the "compatibility" directly.

On the contrary, currently it is easier than ever to use the programming language Kotlin in a Java environment!

For comparison, Forge usually has to be installed on the server AND even manually by the user, Kotlin has to be added ONLY as a default plugin by the administrator

Since Kotlin also works directly with Java and refers to it several times, Kotlin is indirectly a Java framework, but I would not go that far :D

It is a fact that nowadays it is not a technical problem to use Kotlin instead of Java or with Java, so that such a feature is important for the current market.

As an example: new Android apps are nowadays also developed natively with Kotlin (problems? NO!)

Since this plugin has unfortunately already 'missed' some new systems, it would be a pity to miss this system as well. For people like me this would be a reason to change to another system or to develop a plugin which offers these basic simple functions and extended support.

And if you need help inserting the Kotlin-Dependency, you can create a community call, maybe even report me yourself.

Partially taken from closed issue #749

Earthcomputer

Earthcomputer commented on Aug 25, 2020

@Earthcomputer
Member

There is no reason to spam. Lack of kotlin support in the plugin is a technical limitation. If we didn't see the merits of kotlin, do you really think MinecraftDev itself would be written in kotlin?

davenathanael

davenathanael commented on Sep 11, 2020

@davenathanael

Hello, sorry for replying to an old-ish issue. I'm new to JVM dependency-management world such as Gradle/Maven (coming from JS/Python/Go), and would like to try on developing Spigot plugins.

I'm currently trying to use Kotlin as the language. I understand MinecraftDev currently does not support Kotlin yet, but with the spirit of "getting the minimal workspace right" (what I feel from this project, similar to "bootstraper", boilerplate, scaffolding, generator, etc. from other languages), do you guys have a migration guide for migrating Java-Gradle Spigot plugin MinecraftDev project to use Kotlin? I have looked around at some repositories here on GitHub but seems everyone have their own way to setup the Gradle etc. If that's currently available, or if there's a recommended article/repository that I can refer to, that'd be great, but if there's none currently, that's ok as well. Thanks and cheers :)

Jaimss

Jaimss commented on Sep 11, 2020

@Jaimss
Author

I haven't used the MinecraftDev setup in a while, but iirc it sets up your plugin.yml and leaves you with a project structure similar to this:
src/main/java // java code would go here
I think they also put a Main class in that directory, which I would delete cause its in java.
src/main/resources // plugin.yml, config.yml, etc.

When I do plugins, I just add a folder to that structure at
/src/main/kotlin // kotlin code goes here
I also would usually create a new package inside the kotlin folder called dev.jaims.pluginname, but afaik you don't really need to do that.
Inside there you also have to setup your main class. Here is a quick example of what that might look like in Kotlin.

package dev.jaims.relicthub

import dev.jaims.mcutils.bukkit.log
import dev.jaims.mcutils.bukkit.register
import dev.jaims.relicthub.listener.JoinLeaveListener
import org.bukkit.plugin.java.JavaPlugin

class RelictHub : JavaPlugin() {

    // startup login
    override fun onEnable() {

    }

    // shutdown logic
    override fun onDisable() {

    }
}

You shouldn't need to change much of the build.gradle, but I've copied a recent one I did for a 1.16 paper plugin.

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.4.0'
    id 'com.github.johnrengelman.shadow' version '6.0.0'
}

group 'dev.jaims'
version '1.0'

shadowJar {
    archiveClassifier.set("")
}

repositories {
    mavenCentral()
    maven { url 'https://papermc.io/repo/repository/maven-public/' }
    maven { url 'https://repo.jaims.dev/repository/maven-releases' }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    implementation 'dev.jaims.mcutils:bukkit:2.1.1'
    compileOnly 'com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

I think the only difference is adding the compileKotlin and compileTestKotlin tasks, as well as the kotlin std lib and kotlin plugin. I also added the shadowJar stuff to be able to shade dependencies.

Hopefully this sorta answered what you were asking, but to sum it all up, I would usually just add the two Kotlin tasks, then start writing code at /src/main/kotlin or similar depending on what your package name is and where in your project its located.

davenathanael

davenathanael commented on Sep 12, 2020

@davenathanael

Thank you for your suggestion @Jaimss!

stale

stale commented on Dec 19, 2020

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

7 remaining items

JadeNeoma

JadeNeoma commented on Jun 19, 2022

@JadeNeoma

+1

Schmarni-Dev

Schmarni-Dev commented on Jul 15, 2022

@Schmarni-Dev

+1

mindsolve

mindsolve commented on Jul 16, 2022

@mindsolve

Hi everyone! I would love to see full first class support for Kotlin, especially including all the quick fixes and inspections.
Would donations or putting a "bounty" on this issue help dedicating more time/resources, or would it just needlessly increase pressure?

filename24

filename24 commented on Oct 13, 2022

@filename24

+1

jcurtis06

jcurtis06 commented on Dec 11, 2022

@jcurtis06

+1

flowergardn

flowergardn commented on Jan 7, 2023

@flowergardn

+1

Qubilux

Qubilux commented on Feb 5, 2023

@Qubilux

It seems like it throws internal errors when using Kotlin in Architectury mods too.
https://github.com/minecraft-dev/mcdev-error-report/issues/312#issuecomment-1416067901

T3sT3ro

T3sT3ro commented on Feb 25, 2023

@T3sT3ro

Has there been any work done on this matter and is there some kind of list of things that would have to be implemented (or list of blockers) for this issue to get closed? Maybe if we can all work together then this can be finished.

FaultyFunctions

FaultyFunctions commented on May 28, 2024

@FaultyFunctions

Any news on adding Kotlin support?

KitsuneDev

KitsuneDev commented on Jul 28, 2024

@KitsuneDev

I believe this has been implemented as of the latest update?
Just missing Forge/Architectury templates...

Earthcomputer

Earthcomputer commented on Jul 28, 2024

@Earthcomputer
Member

You can PR any missing templates to https://github.com/minecraft-dev/templates

KitsuneDev

KitsuneDev commented on Jul 28, 2024

@KitsuneDev

Should this issue be closed then, as Kotlin support is already implemented?

RedNesto

RedNesto commented on Jul 28, 2024

@RedNesto
Member

Kotlin support is more than just the creator, I'm working on supporting event listener generation for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DenWav@T3sT3ro@FaultyFunctions@davenathanael@KitsuneDev

        Issue actions

          Kotlin Support · Issue #722 · minecraft-dev/MinecraftDev