Skip to content

Conversation

@yluom
Copy link
Owner

@yluom yluom commented Jun 5, 2025

Summary

  • update README with links and mention 2024 Kotlin support
  • configure Maven to compile Kotlin from src/main/kotlin
  • set Kotlin jvmTarget to 21 and allow Kotlin test sources
  • add Kotlin utility AoCHelper for the 2024 edition
  • scaffold day 1 example in Kotlin and create resource folders

Testing

  • mvn -q test (fails: PluginResolutionException - unable to download kotlin-maven-plugin)

https://chatgpt.com/codex/tasks/task_e_6841baad38708326bff0314ec5f2f783

Summary by CodeRabbit

  • New Features

    • Added support for solving Advent of Code 2024 puzzles in Kotlin, including a helper class to standardize input handling and execution.
    • Introduced an initial Day 1 solution template for 2024 with input file handling.
  • Documentation

    • Updated the README to reflect support for multiple Advent of Code years and added useful links.
  • Chores

    • Updated build configuration to support Kotlin source directories and increased the JVM target version.

@coderabbitai
Copy link

coderabbitai bot commented Jun 5, 2025

Walkthrough

The changes introduce Kotlin support for Advent of Code 2024 solutions. A new abstract helper class standardizes input handling and execution for puzzle solvers. An initial Day 1 solution class and input files are added, and the build system is updated to support Kotlin sources and JVM 21. The README is updated accordingly.

Changes

File(s) Change Summary
README.md Updated title, added 2024 mention, brief repo description, and a new "Useful links" section.
pom.xml Added Kotlin source directories, set JVM target to 21, specified test source dirs.
src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt Added abstract class AoCHelper with input utilities and a dynamic main runner.
src/main/kotlin/fr/lmo/aoc2024/D01.kt Added D01 class extending AoCHelper and its main function for Day 1 solution.
src/main/resources/2024/d01/input-test.txt
src/main/resources/2024/d01/input.txt
Added test and actual input files for Day 1, each containing "TODO".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainFunction
    participant AoCHelper
    participant D01

    User->>MainFunction: Run main(args)
    MainFunction->>AoCHelper: AoCHelper.main(args)
    AoCHelper->>D01: Instantiate D01 via reflection
    AoCHelper->>D01: Call run()
    D01->>AoCHelper: getTestInputPath()
    D01->>AoCHelper: readFile(path)
    D01->>User: Print file contents
Loading

Poem

A hop and a skip, new Kotlin in tow,
Advent of Code 2024, ready to go!
Helpers and inputs, all neat and new,
JVM twenty-one, we’re leaping through.
With every new puzzle, solutions take flight—
Rabbits code swiftly, from morning to night!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
pom.xml (1)

89-89: 💡 Verification agent

🧩 Analysis chain

Address the plugin resolution issue mentioned in PR description.

The PR description mentions a PluginResolutionException when running mvn -q test due to kotlin-maven-plugin download issues. This might be related to the Kotlin version or missing repository configuration.


🏁 Script executed:

#!/bin/bash
# Description: Check Maven repository configuration and Kotlin plugin availability

# Check if Maven can resolve the kotlin-maven-plugin
mvn help:describe -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-maven-plugin -Dversion=1.9.0

# Check Maven settings and active repositories  
mvn help:effective-settings | grep -A 5 -B 5 "repository"

Length of output: 345


#!/bin/bash
set -e

# Search for kotlin-maven-plugin in pom.xml
rg -C2 -n "kotlin-maven-plugin" pom.xml

# Check for <pluginRepositories> section
rg -C2 -n "<pluginRepositories>" pom.xml

# Check for <repositories> section
rg -C2 -n "<repositories>" pom.xml

#!/bin/bash
set -e

# Check for pluginRepositories section in pom.xml
rg -C2 -n "<pluginRepositories>" pom.xml

# Check for repositories section in pom.xml
rg -C2 -n "<repositories>" pom.xml

🏁 Script executed:

#!/usr/bin/env bash
set -e

# Check if <pluginRepositories> is declared
rg -n "<pluginRepositories>" pom.xml || echo "No <pluginRepositories> section found in pom.xml"

# Check if <repositories> is declared
rg -n "<repositories>" pom.xml || echo "No <repositories> section found in pom.xml"

# Verify kotlin-maven-plugin definition
rg -n "<artifactId>kotlin-maven-plugin</artifactId>" pom.xml || echo "kotlin-maven-plugin not referenced in pom.xml"

Length of output: 409


Add explicit pluginRepositories for Kotlin Maven Plugin resolution

It looks like your pom.xml defines the Kotlin plugin (line 15) but has no <pluginRepositories> or <repositories> section—Maven falls back to central by default, but if your build environment overrides or mirrors central you’ll need to declare it explicitly. Please add something like:

<project>
  …
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>

  <repositories>
    <repository>
      <id>central</id>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  …
</project>

This ensures kotlin-maven-plugin (version 1.9.0) can always be fetched.

🧹 Nitpick comments (3)
src/main/kotlin/fr/lmo/aoc2024/D01.kt (1)

6-6: Consider uncommenting the real input line.

Once you have the actual puzzle input, uncomment this line to process the real input data alongside the test input.

src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt (2)

13-21: Fix the directory naming collision risk.

The directoryName() method uses simpleName.lowercase() which could cause collisions if class names differ only in case. Consider using the actual class name or a more robust naming strategy.

-private fun directoryName(): String = this::class.java.simpleName.lowercase()
+private fun directoryName(): String = this::class.java.simpleName.lowercase().let { name ->
+    if (name.startsWith("d") && name.length == 3) name else name
+}

37-54: Improve error handling specificity and add constructor validation.

The current exception handling catches all exceptions generically. Consider more specific error handling and validate that target classes have the expected no-arg constructor.

fun main(args: Array<String>) {
    if (args.isEmpty()) {
        println("Arg should contain classname")
        return
    }
    val className = args[0]
    try {
        val clazz = Class.forName("${AoCHelper::class.java.packageName}.$className")
            .asSubclass(AoCHelper::class.java)
+       
+       // Validate constructor exists
+       clazz.getDeclaredConstructor()
+       
        val instance = clazz.getDeclaredConstructor().newInstance()
        instance.run()
-   } catch (e: Exception) {
+   } catch (e: ClassNotFoundException) {
+       println("Class not found: ${AoCHelper::class.java.packageName}.$className")
+   } catch (e: NoSuchMethodException) {
+       println("Class $className must have a no-arg constructor")
+   } catch (e: Exception) {
        e.printStackTrace()
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c66ab6c and a0f7f9d.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • pom.xml (2 hunks)
  • src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt (1 hunks)
  • src/main/kotlin/fr/lmo/aoc2024/D01.kt (1 hunks)
  • src/main/resources/2024/d01/input-test.txt (1 hunks)
  • src/main/resources/2024/d01/input.txt (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/kotlin/fr/lmo/aoc2024/D01.kt (1)
src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt (2)
  • readFile (30-30)
  • getTestInputPath (26-26)
🔇 Additional comments (11)
src/main/resources/2024/d01/input.txt (1)

1-1: Appropriate placeholder for puzzle input.

This TODO placeholder is the correct approach for scaffolding Advent of Code input files. The actual puzzle input will be added when working on day 1.

src/main/resources/2024/d01/input-test.txt (1)

1-1: Appropriate placeholder for test input.

Consistent with the main input file, this TODO placeholder follows the correct scaffolding pattern for Advent of Code test input files.

README.md (1)

1-8: Well-structured documentation updates.

The README updates appropriately reflect the repository's expanded scope to include Advent of Code 2024 with Kotlin support. The title change and useful links section improve clarity and navigation.

pom.xml (3)

26-28: Correct Kotlin source directory configuration.

Adding src/main/kotlin to the source directories properly enables Kotlin compilation alongside existing Java sources.


42-45: Good test source directory configuration.

Explicitly configuring both Kotlin and Java test source directories ensures proper test compilation for mixed-language projects.


41-41:

Details

❓ Verification inconclusive

Verify JVM target compatibility.

JVM target 21 is quite recent. Ensure your runtime environment supports Java 21, especially given the PR description mentions build failures.


🏁 Script executed:

#!/bin/bash
# Description: Check if the Kotlin version supports JVM target 21 and verify current Java version compatibility

# Check current Java version
java -version

# Check Maven Java version
mvn -version | head -3

Length of output: 313


🏁 Script executed:

#!/bin/bash
# Inspect pom.xml for Kotlin plugin and Java version settings

echo "== Kotlin Maven plugin configuration =="
rg -n '<artifactId>kotlin-maven-plugin' pom.xml -A5

echo
echo "== Kotlin version property =="
rg -n '<kotlin.version>' pom.xml

echo
echo "== Java version property =="
rg -n '<java.version>' pom.xml

echo
echo "== Maven Compiler plugin configuration =="
rg -n '<artifactId>maven-compiler-plugin' pom.xml -A5

echo
echo "== Compiler source/target settings =="
rg -n '<source>' pom.xml -A3
rg -n '<target>' pom.xml -A3

Length of output: 1982


Confirm Java 21 support in build environment

Please verify that your local and CI environments are running Java 21 (or later) to match the following settings in pom.xml:

  • Kotlin plugin’s <jvmTarget>21</jvmTarget>
  • Maven Compiler plugin’s <source>21</source> and <target>21</target>

Our sandbox reported JDK 17 and could not run mvn -version, so ensure all build agents have at least Java 21 installed. Otherwise, consider lowering the target to Java 17 to avoid compilation failures.

src/main/kotlin/fr/lmo/aoc2024/D01.kt (2)

3-8: Well-structured solution class following the helper pattern.

The class structure correctly extends AoCHelper and implements the run method. The approach of testing with test input first before switching to real input is a good Advent of Code practice.


10-12:

Details

✅ Verification successful

Verify the main function delegation pattern.

The main function delegates to AoCHelper.main(args) rather than directly instantiating and running D01. Ensure this pattern correctly resolves to running the D01 solution.


🏁 Script executed:

#!/bin/bash
# Description: Verify AoCHelper.main implementation to understand the delegation pattern

# Search for AoCHelper main method implementation
ast-grep --pattern $'companion object {
  $$$
  fun main($_) {
    $$$
  }
  $$$
}'

# Alternative search for main method in AoCHelper
rg -A 10 "fun main" src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt

Length of output: 626


🏁 Script executed:

#!/bin/bash
# Locate the D01 solution class
rg -n "class D01" -n src/main/kotlin/fr/lmo/aoc2024

# Show the contents of D01.kt
sed -n '1,200p' src/main/kotlin/fr/lmo/aoc2024/D01.kt

# Locate the AoCHelper class definition
rg -n "class AoCHelper" -n src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt

# Display the beginning of AoCHelper.kt to inspect the abstract base and run() method
sed -n '1,200p' src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt

Length of output: 2257


Delegation pattern verified and correct.
The main in D01.kt hands off to AoCHelper.main(args), which uses reflection to load the class named in args[0] and invoke its run() method. Running with "D01" correctly executes D01.run(). No changes required.

src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt (3)

1-5: LGTM: Clean package structure and appropriate imports.

The package declaration and imports are well-organized and include only the necessary dependencies for file operations.


7-11: LGTM: Good use of abstract class with template method pattern.

The abstract class design provides a clean template method pattern where subclasses implement puzzle-specific logic while inheriting common utility functionality.


30-35: LGTM: Well-implemented file reading utilities with proper resource management.

The file reading methods are well-designed, and the list() method correctly uses .use {} for proper resource management with streaming.

Comment on lines +22 to +25

private fun path(name: String): Path =
Paths.get("src", "main", "resources", "2024", directoryName(), fileName(name))

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using classpath resources for better JAR compatibility.

The current path construction uses filesystem paths which may not work when the application is packaged in a JAR file. Consider using classpath resources instead.

-private fun path(name: String): Path =
-    Paths.get("src", "main", "resources", "2024", directoryName(), fileName(name))
+private fun path(name: String): Path {
+    val resourcePath = "/2024/${directoryName()}/${fileName(name)}"
+    return this::class.java.getResource(resourcePath)?.toURI()?.let { Paths.get(it) }
+        ?: throw IllegalStateException("Resource not found: $resourcePath")
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private fun path(name: String): Path =
Paths.get("src", "main", "resources", "2024", directoryName(), fileName(name))
private fun path(name: String): Path {
val resourcePath = "/2024/${directoryName()}/${fileName(name)}"
return this::class.java
.getResource(resourcePath)
?.toURI()
?.let { Paths.get(it) }
?: throw IllegalStateException("Resource not found: $resourcePath")
}
🤖 Prompt for AI Agents
In src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt around lines 22 to 25, the method
constructs file system paths directly, which can fail when running from a JAR.
Refactor the path function to load resources using the class loader's
getResource or getResourceAsStream methods to access files from the classpath,
ensuring compatibility when packaged as a JAR.

Comment on lines +26 to +28
fun getTestInputPath(): Path = path("input-test")

fun getInputPath(): Path = path("input")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical bug: getTestInputPath() will return incorrect filename when test property is set.

The getTestInputPath() method calls path("input-test"), but the fileName() method will append "-test" again if the system property "test" is true, resulting in "input-test-test.txt" instead of "input-test.txt".

-fun getTestInputPath(): Path = path("input-test")
+fun getTestInputPath(): Path = 
+    Paths.get("src", "main", "resources", "2024", directoryName(), "input-test.txt")

Or create a separate method that bypasses the system property logic:

+private fun pathWithoutTestSuffix(name: String): Path =
+    Paths.get("src", "main", "resources", "2024", directoryName(), "$name.txt")
+
-fun getTestInputPath(): Path = path("input-test")
+fun getTestInputPath(): Path = pathWithoutTestSuffix("input-test")

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/main/kotlin/fr/lmo/aoc2024/AoCHelper.kt around lines 26 to 28, the
getTestInputPath() method calls path("input-test"), but since path() appends
"-test" when the "test" system property is true, this results in
"input-test-test.txt" instead of "input-test.txt". To fix this, create a
separate method that returns the path for "input-test" without applying the
"-test" suffix logic, bypassing the system property check, or adjust
getTestInputPath() to directly return the correct filename without double
appending "-test".

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants