All skills
kotlin avatar

/kotlin-tooling-java-to-kotlin

@8fc58af official
by kotlinkotlin/kotlin-agent-skills1.1k stars
42

Use when converting Java source files to idiomatic Kotlin, when user mentions "java to kotlin", "j2k", "convert java", "migrate java to kotlin", or when working with .java files that need to become .kt files. Handles framework-aware conversion for Spring, Lombok, Hibernate, Jackson, Micronaut, Quarkus, Dagger/Hilt, RxJava, JUnit, Guice, Retrofit, and Mockito.

Use this Skill: https://skilld.dev/gh/kotlin/kotlin-agent-skills/kotlin-tooling-java-to-kotlin

This session only. Nothing lands on disk.

referencesframeworksMICRONAUT.md

≈833 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Micronaut Conversion Guide

When This Applies

This guide applies when the Java source contains imports matching io.micronaut.*. This covers Micronaut HTTP, Micronaut Data, and Micronaut Security.

Key Rules

1. Constructor injection is the default

Micronaut uses compile-time dependency injection via constructor injection by default. This maps naturally to Kotlin's primary constructor. Remove @Inject when there is only one constructor — Micronaut discovers it automatically.

2. Stereotype annotations

@Singleton, @Controller, @Client, @Repository — preserve these exactly. No annotation site target is needed.

3. @Value annotation

Escape $ in Kotlin to prevent string template interpretation:

@Value("\${config.key}") val configKey: String

4. @Inject field injection → constructor injection

Replace @Inject on fields with constructor parameters in Kotlin's primary constructor. This eliminates lateinit var and makes dependencies immutable.

5. AOP interceptors require open classes

Classes using AOP annotations (@Around, @Introduction, @Cacheable) must be open in Kotlin because Micronaut generates subclass proxies for them at compile time.

6. Bean factories

@Factory classes and their @Bean-annotated methods should be open so Micronaut can manage their lifecycle through subclassing.

7. @ConfigurationProperties

Convert to a class with mutable properties. Use lateinit var for required String properties and var with defaults for primitives. The class must be open.


Examples

Example 1: Micronaut Controller with Constructor Injection

Java:

package com.acme.web;

import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.PathVariable;
import jakarta.inject.Inject;

@Controller("/api/orders")
public class OrderController {

    private final OrderService orderService;
    private final InventoryClient inventoryClient;

    @Inject
    public OrderController(OrderService orderService, InventoryClient inventoryClient) {
        this.orderService = orderService;
        this.inventoryClient = inventoryClient;
    }

    @Get("/{id}")
    public OrderDto getOrder(@PathVariable Long id) {
        return orderService.findById(id);
    }

    @Get
    public List<OrderDto> listOrders() {
        return orderService.findAll();
    }
}

Kotlin:

package com.acme.web

import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.PathVariable

@Controller("/api/orders")
class OrderController(
    private val orderService: OrderService,
    private val inventoryClient: InventoryClient
) {

    @Get("/{id}")
    fun getOrder(@PathVariable id: Long): OrderDto? {
        return orderService.findById(id)
    }

    @Get
    fun listOrders(): List<OrderDto> {
        return orderService.findAll()
    }
}

Key changes:

  • @Inject is removed — Micronaut auto-discovers the single constructor.
  • The jakarta.inject.Inject import is removed because it is no longer referenced.
  • Constructor parameters become private val in the primary constructor.
  • Return type OrderDto becomes OrderDto? where the service may return null.

Source: SKILL.md on GitHub

No alerts16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a methodology for converting Java source code to Kotlin. While the logic is sound and focused on development tasks, it possesses an indirect prompt injection surface by processing untrusted source code and performing file system operations.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 8fc58af. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 weeks ago.

Activeupdated 7 months ago
metadata
{
  "author": "JetBrains",
  "version": "1.0.0"
}
  • kotlin
  • java
  • migration
  • spring
  • hibernate
  • jackson
  • junit
  • rxjava
  • retrofit
  • mockito
  • conversion

README badge

README badge for kotlin/kotlin-agent-skills/kotlin-tooling-java-to-kotlin

Converts Java source files to idiomatic Kotlin using a structured 4-step methodology with framework-aware handling for Spring, Lombok, Hibernate, Jackson, Micronaut, Quarkus, Dagger/Hilt, RxJava, JUnit, Guice, Retrofit, and Mockito. Preserves git history through two-phase renames and supports batch conversion with dependency ordering.

Generated from the current SKILL.md.

What frameworks does this skill handle?
Spring, Lombok, Hibernate, Jackson, Micronaut, Quarkus, Dagger/Hilt, RxJava, JUnit, Guice, Retrofit, and Mockito. The skill detects which frameworks are in use by scanning import statements and loads only the relevant framework guides.
Does this skill preserve git blame history?
Yes. It uses a two-phase approach: first rename the file with `git mv`, then replace the content in a separate commit so the rename is tracked separately from the conversion changes.
Can this skill convert multiple Java files at once?
Yes. For batch conversions, it sorts files by dependency order (leaf files first), converts one at a time through the full workflow, and updates cross-references as needed.
What happens if conversion fails the verification step?
The skill reverts to the previous conversion step and retries. It checks five invariants at each step and verifies output by compilation, tests, and annotation site targets.
Does this handle Java interop edge cases like platform types and checked exceptions?
Yes. The skill documents and handles Kotlin keyword conflicts, SAM conversion ambiguity, platform types, @JvmStatic/@JvmField/@JvmOverloads, checked exceptions, and wildcard generics in a separate known-issues reference.

Generated from the current SKILL.md. These answers refresh after source changes.