Skip to content

Replace gradle.properties with ModConfig object for IDE completion support#2

Merged
Meatwo310 merged 6 commits intoforge-1.20.1from
copilot/fix-d07ad965-627b-4384-bf81-17d12b00c737
Sep 25, 2025
Merged

Replace gradle.properties with ModConfig object for IDE completion support#2
Meatwo310 merged 6 commits intoforge-1.20.1from
copilot/fix-d07ad965-627b-4384-bf81-17d12b00c737

Conversation

Copy link
Contributor

Copilot AI commented Sep 25, 2025

Eliminates gradle.properties dependency for mod configuration by defining all mod and environment settings directly in build.gradle.kts using a ModConfig object, providing full IDE completion support and type safety.

Problem

The current build.gradle.kts manually declares each property from gradle.properties using by project delegation, resulting in verbose and repetitive code:

val mod_version: String by project
val mod_group_id: String by project
val mod_id: String by project
val minecraft_version: String by project
// ... 10+ more similar declarations

This approach requires maintaining mod configuration in a separate gradle.properties file and doesn't provide IDE completion support for the configuration values.

Solution

Replaced the gradle.properties dependency for mod configuration with a self-contained ModConfig object that defines all configuration directly in the build script:

object ModConfig {
    // Environment Properties
    const val minecraftVersion = "1.20.1"
    const val minecraftVersionRange = "[1.20.1,1.21)"
    const val forgeVersion = "47.4.0"
    const val forgeVersionRange = "[47.4,)"
    const val loaderVersionRange = "[47,)"
    const val mappingChannel = "parchment"
    const val mappingVersion = "2023.09.03-1.20.1"
    
    // Mod Properties
    const val modId = "examplemod"
    const val modName = "Example Mod"
    const val modLicense = "MIT"
    const val modVersion = "0.1.0"
    const val modGroupId = "io.github.meatwo310.examplemod"
    const val modAuthors = "Meatwo310"
    const val modDescription = ""
}

// Usage with full IDE completion:
version = "v${ModConfig.modVersion}"
group = ModConfig.modGroupId

The gradle.properties file is now streamlined to contain only essential Gradle JVM settings:

org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

Benefits

  • Full IDE Completion: Type ModConfig. to get complete autocomplete list of all properties
  • Streamlined Configuration: gradle.properties now only contains essential Gradle settings
  • Type Safety: Compile-time validation of all configuration values using const val
  • Better Organization: All configuration grouped logically with clear comments
  • Self-Documenting: Configuration structure immediately visible in build script
  • Refactoring Support: IDE can safely rename/refactor properties across entire project
  • Single Source of Truth: All mod configuration centralized in build script

Changes Made

  • Moved all mod and environment configuration from gradle.properties to ModConfig object
  • Created ModConfig object with all 14 configuration properties as const val
  • Updated all property usages throughout the build script to use ModConfig references
  • Organized properties into logical groups (Environment Properties and Mod Properties)
  • Cleaned up gradle.properties to contain only essential Gradle JVM settings (2 lines)
  • Added clear comments for better documentation

The build script now provides superior IDE support and type safety while maintaining a clean separation between Gradle settings and mod configuration.

Original prompt

This section details on the original issue you should resolve

<issue_title>TODO: build.gradle.ktsのプロパティ参照をなんとかする</issue_title>
<issue_description>gradle.propertiesから参照してるせいで大変なことに

@file:Suppress("PropertyName")
// ...
val mod_version: String by project
val mod_group_id: String by project
val mod_id: String by project
val minecraft_version: String by project
val minecraft_version_range: String by project
val mapping_channel: String by project
val mapping_version: String by project
val forge_version: String by project
val forge_version_range: String by project
val loader_version_range: String by project
val mod_name: String by project
val mod_license: String by project
val mod_authors: String by project
val mod_description: String by project
```</issue_description>

<agent_instructions>いちいちプロパティをbuild.gradle.ktsで列挙してられないので、よりKotlin DSLらしい方法で書き換えてください</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
---- **Additional instructions:**

いちいちプロパティをbuild.gradle.ktsで列挙してられないので、よりKotlin DSLらしい方法で書き換えてください

Fixes #1


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Meatwo310 <72017364+Meatwo310@users.noreply.github.com>
Copilot AI changed the title [WIP] TODO: build.gradle.ktsのプロパティ参照をなんとかする Refactor build.gradle.kts to use Kotlin DSL-friendly property access Sep 25, 2025
Copilot AI requested a review from Meatwo310 September 25, 2025 09:06
@Meatwo310
Copy link
Owner

@copilot
gradle.propertiesを使わない方法で再度提案してください
補完の効く環境でパラメータ類を過不足なく列挙できることが目標です

…pport

Co-authored-by: Meatwo310 <72017364+Meatwo310@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 25, 2025

@copilot
gradle.propertiesを使わない方法で再度提案してください
補完の効く環境でパラメータ類を過不足なく列挙できることが目標です

gradle.propertiesを使わない方法に変更しました。すべての設定値をModConfigオブジェクトとして直接build.gradle.ktsに定義することで、IDEの補完機能が完全に利用できるようになります。

変更内容:

  • gradle.propertiesへの依存を完全に削除
  • ModConfigオブジェクトですべてのパラメータを定義 (14個の設定値を過不足なく列挙)
  • const valによる型安全性とコンパイル時検証
  • ModConfig.プロパティ名でIDE補完が効く

コミット: a6aa168

Copilot AI changed the title Refactor build.gradle.kts to use Kotlin DSL-friendly property access Replace gradle.properties with ModConfig object for IDE completion support Sep 25, 2025
Copy link
Owner

@Meatwo310 Meatwo310 left a comment

Choose a reason for hiding this comment

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

よくできました

@Meatwo310
Copy link
Owner

@copilot
gradle.propertiesだけ整理しておいて
最初の2行以外はいらなくなったはず

Co-authored-by: Meatwo310 <72017364+Meatwo310@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 25, 2025

@copilot
gradle.propertiesだけ整理しておいて
最初の2行以外はいらなくなったはず

gradle.propertiesを整理しました。最初の2行(JVM設定)のみを残し、ModConfigオブジェクトに移行済みのmod/environment設定を全て削除しました。

変更内容:

  • 19行の不要なプロパティを削除
  • Gradle JVM設定のみを保持
  • ModConfigオブジェクトで全ての設定を管理

コミット: 7fa6bc5

Co-authored-by: Meatwo310 <72017364+Meatwo310@users.noreply.github.com>
Copy link
Owner

@Meatwo310 Meatwo310 left a comment

Choose a reason for hiding this comment

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

👍

@Meatwo310 Meatwo310 marked this pull request as ready for review September 25, 2025 10:29
@Meatwo310 Meatwo310 merged commit 352cc97 into forge-1.20.1 Sep 25, 2025
6 checks passed
@Meatwo310 Meatwo310 deleted the copilot/fix-d07ad965-627b-4384-bf81-17d12b00c737 branch September 25, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TODO: build.gradle.ktsのプロパティ参照をなんとかする

2 participants